yfmilu / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

DrawerActions is (still) leaking the parent listener #147

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Espresso version: 2.1

What steps will reproduce the problem?
1. Use DrawerActions.openDrawer(R.id.drawer_view);
2. The activity gets destroyed (e.g. moving on to next test)
3. The activity is not GCed, it's held in memory by DrawerActions

DrawerActions.IdlingDrawerListener has an "instance" static field, and a 
"parentListener" instance field. When DrawerActions.unregisterListener() is 
called, it removes its own listener and replaces it with "parentListener", 
however it fails to clear its reference to "parentListener".

Proposed fix:

In DrawerActions.unregisterListener(), replace this:

        if (existingListener instanceof IdlingDrawerListener) {
          Espresso.unregisterIdlingResources((IdlingResource) existingListener);
          drawer.setDrawerListener(((IdlingDrawerListener) existingListener).parentListener);
        }

with this:

        if (existingListener instanceof IdlingDrawerListener) {
          IdlingDrawerListener idleDrawerListener = (IdlingDrawerListener) existingListener;
          Espresso.unregisterIdlingResources(idleDrawerListener);
          drawer.setDrawerListener(idleDrawerListener.parentListener);
          idleDrawerListener.parentListener = null;
        }

Here's the chain of references:

* GC ROOT
* static 
com.squareup.instrumentation.framework.DrawerActions$IdlingDrawerListener.instan
ce
* references 
com.squareup.instrumentation.framework.DrawerActions$IdlingDrawerListener.parent
Listener
* references com.squareup.SomeActivity$2.this$0 (anonymous class extends 
android.support.v4.widget.DrawerLayout$SimpleDrawerListener)
* leaks com.squareup.SomeActivity instance

Original issue reported on code.google.com by p...@squareup.com on 28 Apr 2015 at 2:56

GoogleCodeExporter commented 9 years ago

Original comment by nkors...@google.com on 5 May 2015 at 5:27

GoogleCodeExporter commented 9 years ago
https://android-review.googlesource.com/#/c/150744/

Original comment by eden...@gmail.com on 15 May 2015 at 6:39

GoogleCodeExporter commented 9 years ago

Original comment by slinz...@google.com on 9 Jun 2015 at 2:50