安装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异常,点击就可以进入异常详情界面
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐