Leak - DetachEventCompletable isn't removed when View is removed from ViewTree
ultraon opened this issue · comments
Hello, Thank you very much for that great library.
I think I found a leak when DetachEventCompletable.Listener
isn't removed from listeners inside a View. And this view was multiple times added and removed from ViewTree.
Description:
- when this button is clicked, observe the number of listeners in
android.view.View.ListenerInfo#mOnAttachStateChangeListeners
using debug break-points - Click the button "Add" and then "Remove" a few times
- Then observe the number of listeners in
android.view.View.ListenerInfo#mOnAttachStateChangeListeners
again
Result: the com.uber.autodispose.android.DetachEventCompletable
listeners are not removed using
android.view.View.removeOnAttachStateChangeListener
that should be done in
com.uber.autodispose.android.DetachEventCompletable.Listener.onViewDetachedFromWindow
.
Probably the fix would be simple:
@Override
public void onViewDetachedFromWindow(View v) {
if (!isDisposed()) {
observer.onComplete();
v.removeOnAttachStateChangeListener(this) // <---------- this is a fix.
}
}
Sample project:
TestUberAutodisposeApp.zip
Nice catch! Want to send a PR?