Android开源框架——内存泄漏检测工具 LeakCanary
生活随笔
收集整理的這篇文章主要介紹了
Android开源框架——内存泄漏检测工具 LeakCanary
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開源地址:https://github.com/square/leakcanary
FAQ : https://github.com/square/leakcanary/wiki/FAQ
配置
build.gradle
使用說明
建立RefWatcher全局變量
使用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;@Overridepublic void onCreate() {super.onCreate();refWatcher = LeakCanary.install(this);} }
第二步:監控Activity中的內存泄漏問題
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>第三步:生成的泄漏結果圖
? ? ? ? ? ?? ? ? ?
推薦的好文章:
【1】http://www.jianshu.com/p/0049e9b344b0
【2】http://blog.kamidox.com/android-memory-guide.html
【3】https://corner.squareup.com/2015/05/leak-canary.html
【4】http://www.liaohuqiu.net/cn/posts/leak-canary-read-me/
【5】http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0510/2860.html
總結
以上是生活随笔為你收集整理的Android开源框架——内存泄漏检测工具 LeakCanary的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android开源框架——图片加载与缓存
- 下一篇: Android自定义Applicatio