引入LeakCanary监听内存泄漏
一添加依赖
debugCompile ‘com.squareup.leakcanary:leakcanary-android:1.5.4’
releaseCompile ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5.4’
releaseCompile ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5.4’
二在application里添加
public class TestApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
initLeakCanary();
}
private RefWatcher mRefWatcher;
private void initLeakCanary() {
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
mRefWatcher = RefWatcher.DISABLED;
return;
}
mRefWatcher = LeakCanary.install(this);
}
}
@Override
public void onCreate() {
super.onCreate();
initLeakCanary();
}
private RefWatcher mRefWatcher;
private void initLeakCanary() {
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
mRefWatcher = RefWatcher.DISABLED;
return;
}
mRefWatcher = LeakCanary.install(this);
}
}