LeakCanary 不会捕获我故意添加的泄漏。我错过了什么?
LeakCanary doesn't catch leaks that I have deliberately added. What am I missing?
我们集成了 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
class
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 对象的引用一直存在?
您可能需要将 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'
我们集成了 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
class
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 对象的引用一直存在?
您可能需要将 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'