pwittchen / prefser

Wrapper for Android SharedPreferences with object serialization and RxJava Observables
Apache License 2.0
229 stars 26 forks source link

OnSharedPreferenceChangeListener is garbage collected #159

Closed ubuntudroid closed 5 years ago

ubuntudroid commented 5 years ago

Prefser uses SharedPreferences.registerOnSharedPreferenceChangeListener() in Prefser.observePreferences(). As per the documentation of registerOnSharedPreferenceChangeListener():

Caution: 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.

So the current implementation leads to the listener being GCed after some time which leads to changes not being propagated to observers any longer.

There already is a fix in the RxJava1.x branch. I'm currently migrating it to the RxJava2.x branch, PR incoming.

pwittchen commented 5 years ago

Thanks for reporting this issue. PRs are welcome, of course.