您的位置:首页 > 其它

使用开源项目LeakCanary检测应用的内存泄露

2016-11-02 15:41 477 查看
github地址https://github.com/6035233/leakcanary
安装APP的同时会把LeakCanary插件同时安装上去。以后卸载APP的时候LeakCanary也会一起被卸载。应用发布的时候只要注释掉那行intall代码即可。

使用的方法很简单,只需要在项目中添加如下依赖

dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
}

Sync即可使用,使用的方法也简单
在自己的application中这样写

publicclassExampleApplicationextendsApplication {

@OverridepublicvoidonCreate() {
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...
}
}

这样在我们的应用运行过程中就会随时随地发现内存泄露的情况,如果发现内存泄露,OOM,那么通知栏将会弹出通知提示发生oom异常,点击就可以进入异常详情界面

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: