Skip to content

DrawerActions is (still) leaking the parent listener #147

Description

@GoogleCodeExporter
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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions