Tom Burns asked a good question about TableView bindings outliving the view controller. As he said:
I’m asking because I noticed that some of my tableview bindings were outliving the view controller being popped back off the stack and it seemed like unnecessary work was being done…
kzaher of the RxSwift Slack community pointed out the following code as being the culprit:
12345 viewModel.objectCellViewModels.driveNext { (newObjects) -> Void inself.objectCellViewModels.value = newObjects}.addDisposableTo(disposeBag)
Tom fixed the code to use an “[unowned self]” before the newObjects. Such as:
1 |
.driveNext { [unowned self] (newObjects) -> Void in |
Although such memory situations aren’t limited to RxSwift, using RxSwift might encourage such situations to come up more often. It something to watch out for.
Regardless, this is something we all can run into from time to time. I feel fortunate enough to have caught the conversation in the RxSwift Slack community and am grateful to Tom for asking.