Reputation: 335
I noticed when running the Rx debug code from the getting started section (https://github.com/ReactiveX/RxSwift/blob/master/Documentation/GettingStarted.md#debugging-memory-leaks), my resource total does not decrease when using disposed(by: disposeBag) on a subscription. However, if I instead keep a reference to the subscription and call dispose() on it, the resource total decreases.
I use disposed(by:) because I thought it was an easy way to accomplish the same thing, although now I am not sure. Should I avoid relying on this method for the disposal of my subscriptions?
Note: If it matters, I use [weak self] in the closures of my subscriptions.
Upvotes: 1
Views: 1494
Reputation: 33967
The dispose bag will call disposed on all the disposables it is holding when it gets deinit
ed. It is likely that your view controller is not going out of scope, or you are expecting it to dispose the objects before that point.
Upvotes: 3