【发布时间】:2016-01-13 22:47:38
【问题描述】:
有人可以给我一个工作示例,说明如何忽略 LeakCanary 中的某些类吗?
我正在查看此示例以忽略 LeakCanary 中第三方库中的某些类,但我无法弄清楚将其放在我的应用程序中的哪个位置。我把它放在我的应用程序类中,但是这些变量和方法有错误:isInAnalyzerProcess、enableDisplayLeakActivity、应用程序、androidWatcher
public class DebugExampleApplication extends ExampleApplication {
protected RefWatcher installLeakCanary() {
if (isInAnalyzerProcess(this)) {
return RefWatcher.DISABLED;
} else {
ExcludedRefs excludedRefs = AndroidExcludedRefs.createAppDefaults().build();
enableDisplayLeakActivity(application);
ServiceHeapDumpListener heapDumpListener = new ServiceHeapDumpListener(application, DisplayLeakService.class);
final RefWatcher refWatcher = androidWatcher(application, heapDumpListener, excludedRefs);
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
public void onActivityDestroyed(Activity activity) {
if (activity instanceof ThirdPartyActivity) {
return;
}
refWatcher.watch(activity);
}
// ...
});
return refWatcher;
}
}
}
【问题讨论】:
-
是的,那一点文档是一团糟。这些方法似乎是
static方法onLeakCanaryitself。您可以尝试以这种方式调用它们(例如,LeakCanary.isInAnalyzerProcess(this)),看看是否可行。 FWIW,I filed an issue on this.
标签: android memory-leaks leakcanary