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

DrawerActions is (still) leaking the parent listener #147

Open
GoogleCodeExporter opened this issue Jun 4, 2015 · 2 comments
Open

DrawerActions is (still) leaking the parent listener #147

GoogleCodeExporter opened this issue Jun 4, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

https://android-review.googlesource.com/#/c/150744/

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

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

No branches or pull requests

1 participant