I’m having this same issue. Does anybody have a reason for this? My assumption is that if you complete this observable (and I’ve added a disposable callback that is firing so it is being “disposed”), you will NOT have a resources issue. I also noticed as well if you remove the .addDisposableTo(bag) call the resources clear.
This chapter is not about best practices - it’s one of the first chapters in the book and tries to introduce you to some of the basics (I’m sure the text mentions this few times). As you see in the chapter I intentionally drive to readers to “creating the problem” (e.g. not disposing the subscription properly) so that I can introduce resource counting.
I’m just trying to clear this up for myself, I understand that (and like you said it’s been mentioned) a lot of the early stuff is not best practices, but I want to make sure I understand how disposing works with observables that have been “completed.”
Just to be clear, even if I “complete” the observable when the viewWillDisappear is called, I still need to add the observer to the photosViewController.bag for this to be disposed properly.
The way that I read explanation in the book was that adding the selectedPhotosSubject.onCompleted() was something you did instead of adding the observer to the photosViewController.bag, not in addition to it, as it was described as a “slightly more elegant solution.” Thanks for the quick reply by the way.
And I understood, that code .addDisposableTo(photosViewController.bag) can be omitted.
I have tested with RxSwift.Recources.total and there were no memory leaks.
But after this change Xcode warns about unused variable. So you should use _ = ... statement like this: