android . 内存泄露 LeakCanary 使用
2019-10-11 本文已影响0人
MorningandSun
1.build.gradle 添加
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
// Optional, if you use support library fragments:
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'
2.自定义application
public class ExampleApplication extends Application {
@Override public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
// Normal app init code...
}
}
3.在发生内存泄漏的地方会出现提示
4.结束后在模拟器上会出现一个
image.png
点击进去即可查看内存泄漏的地方。