Skip to content
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

AndroidObservable.fromSharedPreferencesChanges(): listener get GC'ed #36

Closed
dsvoronin opened this issue Oct 22, 2014 · 3 comments
Closed

Comments

@dsvoronin
Copy link

Somebody tested this observable?
First time i used it, and it never been called.

Seems like a known issue: http://stackoverflow.com/questions/2542938/sharedpreferences-onsharedpreferencechangelistener-not-being-called-consistently/3104265#3104265

Possible solution: move listener field from method to Operator class.

@Yarikx
Copy link
Contributor

Yarikx commented Oct 27, 2014

Possible workaround is to keep strong reference to the subscription.

I would prefer not to move listener to Operator because in this case we create lifecycle where it should not be. We can not fully solve this issue such way. In any case we should keep strong ref to listener, keeping it explicitly in operator, or implicitly in subscription.

@nsk-mironov
Copy link
Contributor

Totally agree with @Yarikx. fromSharedPreferencesChanges implemented properly and holds a reference to the listener as long as it's needed. The api consumer is the one who responsible for keeping a reference to the Subscription and canceling it when necessary.

@dsvoronin
Copy link
Author

Thank you for detailed explanation. It's clear now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants