我们整合了LeakCanary以帮助我们解决我们认为的内存泄漏问题。为了确保我们已经设置好所有东西,我创建了一个静态引用,不会被删除并告诉leakCanary观看它,
public class Cat {
}
public class Box {
public Cat hiddenCat;
}
public class Docker {
public static Box container;
}
在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();
}
<{1>}类中的
Application
并在 private static RefWatcher sRefWatcher;
@Override
public void onCreate() {
sRefWatcher = LeakCanary.install(this);
}
public static RefWatcher getRefWatcher() {
return sRefWatcher;
}
文件中:
build.gradle
我错过了什么,它永远不会告诉我对schrod对象的引用到处都是?
答案 0 :(得分:1)
您可能需要将build.gradle
依赖关系更新为最新版本(位于此页面上的Getting Started
指南:https://github.com/square/leakcanary),恰好是:
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'