-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReplaySubject leaks subscribers even after unsubscribing? #939
Comments
We're observing the leakage on replaying as well (using version 0.17.0-RC7). It seems that We currently work around the issue by avoiding (non-static) inner classes as subscribers and voiding references to activity/fragment-bound variables explicitly in Any better suggestions of how to handle that? |
I think this issue and some related problems with ReplaySubject are now fixed. Could you confirm & close this issue? |
I can confirm this is fixed for us. |
Thanks @mttkay for the confirmation. |
On Android a common use case is to
cache
orreplay
an observable to UI components that might get temporarily destroyed due to e.g. screen rotations.The biggest challenge on Android when using RxJava is therefore to make sure that no resource leaks occur; since subscribers, however, might be inner classes of an Android Activity or Fragment (if you're unfamiliar: think screen object), those will leak if strong references held within an operator are not released when unsubscribing from the sequence.
I just noticed that when using e.g.
cache
on a long running sequence, and subscribing and unsubscribing multiple times, the observer I subscribe to the sequence never seems to get finalized. Android's StrictMode indeed reports that the observer (and hence the entire screen) is being leaked:I quickly glanced over the
ReplaySubject
subscription handling code, and it looks as if on unsubscribe, it removes the observer from the internal map; maybe that's broken, however?The text was updated successfully, but these errors were encountered: