依赖包
dependencies {
compile ‘com.squareup.leakcanary:leakcanary-android:1.4-beta2’
}
权限清单(构建独立进程leakcanary)
<service android:name="com.squareup.leakcanary.internal.HeapAnalyzerService" android:enabled="false"
android:process=":leakcanary" />
<service
android:name="com.squareup.leakcanary.DisplayLeakService"
android:enabled="false" />
代码里面:
application的代码:
public static RefWatcher getRefWatcher() {
return instance.refWatcher;
}
private RefWatcher refWatcher;
oncreat:
refWatcher =LeakCanary.install(this);
activity的ondestroy:
RefWatcher refWatcher = FrameWorkApplication.getRefWatcher();
refWatcher.watch(this);