使用开源项目LeakCanary检测应用的内存泄露
github地址https://github.com/6035233/leakcanary安装APP的同时会把LeakCanary插件同时安装上去。以后卸载APP的时候LeakCanary也会一起被卸载。应用发布的时候只要注释掉那行intall代码即可。使用的方法很简单,只需要在项目中添加如下依赖dependencies {debugCompile 'com.squar
·
安装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异常,点击就可以进入异常详情界面
更多推荐
已为社区贡献1条内容
所有评论(0)