When should we call addDisposableTo(disposeBag) in RxSwift?

前端 未结 2 1038
故里飘歌
故里飘歌 2021-02-19 19:47

We create a DisposeBag, and a Observable, subscribe the Observable and then addDisposableTo(disposeBag), I know when the

2条回答
  •  余生分开走
    2021-02-19 19:57

    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.

提交回复
热议问题