3
我们已经集成了LeakCanary来帮助我们解决我们认为的内存泄漏问题。为了确保我们的每一件事情树立正确的我创建了一个静态的引用,将不会被删除,并告诉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();
}
在
Application
类
private static RefWatcher sRefWatcher;
@Override
public void onCreate() {
sRefWatcher = LeakCanary.install(this);
}
public static RefWatcher getRefWatcher() {
return sRefWatcher;
}
,并在build.gradle
文件:
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}
我错过了什么,它永远不会告诉我,对schrod对象的引用会一直存在?
的确是固定的。 –