Dan Anderson
Dan Anderson

Reputation: 1124

LeakCanary doesn't catch leaks that I have deliberately added. What am I missing?

We've integrated LeakCanary to help us resolve what we believe are memory leak issues. In order to make sure we have every thing set up right I've created a static reference that will not be removed and told leakCanary to watch it,

public class Cat {
 }

 public class Box {
        public Cat hiddenCat;
 }

public class Docker {
     public static Box container;
}

In the MainActivity

    Box box;
    Cat schrod;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    box = new Box();
    schrod = new Cat();
    box.hiddenCat = schrod;
    Docker.container = box;
    Application.getRefWatcher().watch(schrod);


    System.gc();
}

in the Application class

    private static RefWatcher sRefWatcher;

    @Override
    public void onCreate() {
        sRefWatcher = LeakCanary.install(this);  
    }       
    public static RefWatcher getRefWatcher() {
        return sRefWatcher;
    }

and in the build.gradle file:

 dependencies {
        debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
        releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
 }

What am I missing that it never informs me that the reference to the schrod object sticks around?

Upvotes: 3

Views: 681

Answers (1)

Rock Lee
Rock Lee

Reputation: 9566

You might need to update the build.gradle dependencies to latest version (found on the Getting Started guide on this page: https://github.com/square/leakcanary) which happen to be:

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'

Upvotes: 1

Related Questions