1,Gradle配置依赖
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
2,Application中配置
private RefWatcher refWatcher; public static RefWatcher getRefWatcher(Context context) { return instance.refWatcher; }
public void onCreate() { ... refWatcher = LeakCanary.install(this); ... }
3,需要监控的Activity配置
RefWatcher refWatcher = SkyApplication.getRefWatcher(this); refWatcher.watch(this);