• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
韩亚飞_yue31313_韩梦飞沙
未来的某一天你会觉得现在所做的,大部分很烂,小部分很好
博客园    首页    新随笔    联系   管理    订阅  订阅

安卓 内存 泄漏 工具 LeakCanary 使用

韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com

 

LeakCanary是Square开源了一个内存泄露自动探测神器 。这是项目的github仓库地址:https://github.com/square/leakcanary  。使用非常简单,在build.gradle中引入包依赖:

 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'
 }

在Application中的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);

集成后什么都不用做,按照正常测试,当有内存泄漏发生后,应用会通过系统通知栏发出通知,点击通知就可以进入查看内存泄漏的具体信息。在这里举个实践中的例子。把LeakCanary集成到项目中后,等App启动后一会,系统通知到了,点击通知,跳转到泄漏的详情页面进行查看。

韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
posted @ 2017-08-19 16:20  韩梦飞沙_韩亚飞  阅读(304)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3