Leaking View Model in sink
A sink closure keeps the view model alive forever via a retain cycle.
Codeswift
class SearchViewModel {
var cancellables = Set<AnyCancellable>()
@Published var query = ""
func bind() {
$query
.sink { value in
self.handle(value)
}
.store(in: &cancellables)
}
func handle(_ q: String) { /* ... */ }
}What causes a memory leak in this code?