我是否必须取消订阅已完成的 observable? [英] Do I have to unsubscribe from completed observable?

查看:42
本文介绍了我是否必须取消订阅已完成的 observable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个 observable 完成,我是否仍然需要取消订阅/处置(在 RxJava2 中)该 observable 以移除 Observer(防止内存泄漏),或者在 onCompleteonCompleteonError 事件发生?

If an observable completes, do I still have to unsubscribe / dispose (in RxJava2) the observable to remove the Observer (prevent memory leaks) or is this handled internally by RxJava once a onComplete or onError event occurs?

SingleCompletableFlowable 等其他类型怎么样

what about other types like Single, Completable, Flowable etc.

推荐答案

是的,你是对的.

流终止后( onComplete/onError 已被调用),订阅者自动取消订阅.您应该能够使用 Subscription 对象上的 isUn​​subscribed() 方法测试这些行为.

After a stream is terminated ( onComplete / onError has been called ), subscriber unsubscribes automatically. You should be able to test these behaviors using isUnsubscribed() method on the Subscription object.

这篇关于我是否必须取消订阅已完成的 observable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆