1,添加依赖
debugCompile ‘com.squareup.leakcanary:leakcanary-android:1.3’
releaseCompile ‘com.squareup.leakcanary:leakcanary-android-no-op:1.3’
2 初始化
public class MyApplication extends Application {
private static RefWatcher mRefWatcher;
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
mRefWatcher = LeakCanary.install(this);
}
public static RefWatcher getRefWatcher() {
return mRefWatcher;
}
}
3 检测
RefWatcher refWatcher = MyApplication.getRefWatcher();
refWatcher.watch(this);
在activity的onCreate中检测就可以了,如果出现内存泄露就会在状态栏有提示;