We create a DisposeBag
, and a Observable
, subscribe the Observable
and then addDisposableTo(disposeBag)
, I know when the
If you are certain that the observable completes in a deterministic way - like using just
in your example, or using take
, takeUntil
, etc. -, you may choose to not use the DisposeBag.
You might get a compiler warning, that actually explains this behavior well and how to work around it. But in general, it is more future-proof if you use DisposeBag anyway.
See: Unused disposable warning
Dispose bags are used to return ARC like behavior to RX. When a DisposeBag is deallocated, it will call dispose on each of the added disposables.
It is used to dispose of old references that you pass in the closure and resources that are not needed anymore(and which were apparently not used): for example an open HTTP connection, a database connection or a cache.
So if we have any resources that can be left, you should call it.
More in this article.