名称 | LeakCanary |
---|---|
语言 | Android |
平台 | GitHub |
作者 | square |
链接 | 点此进入 |
日常工作中开发APP,我们很多习惯不好的代码风格可能会带来内存溢出,内存溢出在每个APP多多少少都会出现,我们只要用对应的检测工具,然后检测后修改即可。今天给大家推荐内存溢出检测工具LeakCanary,将该工具集成到项目后,运行APP,如果出现内存溢出,则会在通知栏显示通知,并提醒内存溢出的位置,大大方便我们对APP内存溢出的检测。
使用方法:
1、在build.gradle添加依赖:
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.2'
}
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、然后运行APP并测试,如果测试过程中出现内存溢出,会在通知栏显示Notification提示。