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

GC removes preference listeners #69

Closed
ubuntudroid opened this issue Feb 8, 2017 · 0 comments
Closed

GC removes preference listeners #69

ubuntudroid opened this issue Feb 8, 2017 · 0 comments

Comments

@ubuntudroid
Copy link
Contributor

In the constructor of RXSharedPreferences a preference listener created and registered using registerOnSharedPreferenceChangeListener(). The documentation of this method states:

The preference manager does not currently store a strong reference to the listener. You must store a strong reference to the listener, or it will be susceptible to garbage collection. We recommend you keep a reference to the listener in the instance data of an object that will exist as long as you need the listener.

That's why it is very important for developers to keep a reference to the RxSharedPreferences instance as long as one needs to listen to changes. I just stumbled upon this issue myself - kept me busy for around an hour before I found the culprit. Thought I was using the library wrong. We should update the README so it states clearly that it is necessary to keep a RxSharedPreferences reference. I'll propose an according change later today.

ubuntudroid added a commit to ubuntudroid/rx-preferences that referenced this issue Feb 8, 2017
f2prateek added a commit that referenced this issue Mar 9, 2017
#69 Add remark about keeping strong reference to RXSharedPreferences
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

2 participants