1、引入库
2、操作APP,分析结果
3、如果是复杂的问题可以导出hprof文件到android studio 中继续分析
官方地址:
GitHub - square/leakcanary: A memory leak detection library for Android and Java.
https://github.com/square/leakcanary
1、引入库
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、初始化
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
return;
}
LeakCanary.install(this);
}
}
为了分析内存泄漏,我们写一个简单的单例泄漏的例子: