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

配置 
build.gradle

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

使用说明

  1. 建立RefWatcher全局变量

  2. 使用RefWatcher去监控引用,Activity,Fragment等中的内存泄漏

例子

第一步:定义RefWathcher全局变量

package com.app.client;

import android.app.Application;
import android.content.Context; import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher; public class MyApplication extends Application { public static RefWatcher getRefWatcher(Context context){ MyApplication application = (MyApplication) context.getApplicationContext();
return application.refWatcher;
} private RefWatcher refWatcher; @Override
public void onCreate() {
super.onCreate();
refWatcher = LeakCanary.install(this);
}
}

第二步:监控Activity中的内存泄漏问题

package com.app.client;

import android.app.Application;
import android.content.Context; import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher; public class MyApplication extends Application { public static RefWatcher getRefWatcher(Context context){ MyApplication application = (MyApplication) context.getApplicationContext();
return application.refWatcher;
} private RefWatcher refWatcher; @Override
public void onCreate() {
super.onCreate();
refWatcher = LeakCanary.install(this);
}
}

Manifest配置

 <application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

第三步:生成的泄漏结果图

                   

安卓 内存泄漏检测工具 LeakCanary 使用的更多相关文章

  1. android 内存泄漏检测工具 LeakCanary 泄漏金丝雀

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com 内存泄漏检测工具 android 内存泄漏检测工具 ======== 内存泄漏 就是  无用的对 ...

  2. Android 内存泄漏检测工具 LeakCanary(Kotlin版)的实现原理

    LeakCanary 是一个简单方便的内存泄漏检测框架,做 android 的同学基本都收到过 LeakCanary 检测出来的内存泄漏.目前 LeakCanary 最新版本为 2.7 版本,并且采用 ...

  3. Cocos开发中性能优化工具介绍之Visual Studio内存泄漏检测工具——Visual Leak Detector

    那么在Windows下有什么好的内存泄漏检测工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检测功能,我们可以使用第三方工具Visual Leak Detector(以下简 ...

  4. C++内存泄漏检测工具

    C++内存泄漏检测工具 1.VC自带的CRT:_CrtCheckMemory   调试器和 CRT 调试堆函数 1.1用法: /************************************ ...

  5. C/C++的内存泄漏检测工具Valgrind memcheck的使用经历

    Linux下的Valgrind真是利器啊(不知道Valgrind的请自觉查看参考文献(1)(2)),帮我找出了不少C++中的内存管理错误,前一阵子还在纠结为什么VS 2013下运行良好的程序到了Lin ...

  6. 内存泄漏检测工具VLD在VS2010中的使用举例

    Visual LeakDetector(VLD)是一款用于Visual C++的免费的内存泄露检测工具.它的特点有:(1).它是免费开源的,采用LGPL协议:(2).它可以得到内存泄露点的调用堆栈,可 ...

  7. 【转】Unix下C程序内存泄漏检测工具Valgrind安装与使用

    Valgrind是一款用于内存调试.内存泄漏检测以及性能分析的软件开发工具. Valgrind的最初作者是Julian Seward,他于2006年由于在开发Valgrind上的工作获得了第二届Goo ...

  8. LeakCanary内存泄漏检测工具使用步骤

    LeakCanary内存检测工具使用步骤: 第一步,进入app目录下的build.gradle,在最下面找到dependencies{},里面添加如下三行语句: debugCompile 'com.s ...

  9. 【Android内存泄漏检测】LeakCanary使用总结

    一.什么是LeakCanary? LeakCanary就是用来检测Android端内存泄漏的一个工具.能够检测Activity的泄漏 什么是内存泄漏? Java 对象有时也会”长死不死“,GC 拿它没 ...

随机推荐

  1. 【51NOD-0】1058 N的阶乘的长度

    [算法]数学 [题解]n!的位数相当于ans=log10(n!)上取整,然后就可以拆出来加了. 可以用log10(i)或log(i)/log(10) 阶乘好像有个斯特林公式…… #include< ...

  2. [IOS]vmxsmc.exe已停止工作 VMware11 Unlocker for Mac OSX无法使用的解决办法.

    今天我帮同事安装VMware workstation12后发现之前的unlocker已经无法进行解锁了(就是VMware新建虚拟机无App Mac选项) 使用unlocker会出现vmsxmc.exe ...

  3. this的九种常用场景(转子jb51.net)

    [场景1]全局环境中的this指向全局对象 ; alert(a); b = ; alert( ; [场景2]对象内部函数的this指向调用函数的当前对象 ; var bar = { a: , test ...

  4. mybatis 显示 sql日志

    #项目日志logging.level.com.zhang.com=debug #mybatis sql相关日志显示logging.level.org.mybatis.spring=DEBUGloggi ...

  5. Java——关于static关键字的那些事总结

    前言: 先说说今天为啥要谈这个东西,虽然学Java已经有两年了,但是今天,本着温故而知新的态度,仔细的第三次翻看了<Head Firt Java>这本书,虽然这本书介绍的很多东西都特别基础 ...

  6. Perl6 Bailador框架(6):获取用户输入

    use v6; use Bailador; get '/' => sub { ' <html> <head><title></title>< ...

  7. imx6设备树pinctrl解析【转】

    转自:http://blog.csdn.net/michaelcao1980/article/details/50730421 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在移植linu ...

  8. sicily 1059. Exocenter of a Trian

    Description Given a triangle ABC, the Extriangles of ABC are constructed as follows: On each side of ...

  9. 005 JAVA多线程和并发基础面试问答(转载)

    原文链接:http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-answers/ 多线程和并发问题是Ja ...

  10. jQuery 选中tr下面的第某个td

    1.问题描述 点击 table 中的某行 tr,获取该 tr 下的第一个 td 标签下的< input type="hidden" value="92"/ ...