开源地址:https://github.com/square/leakcanary
FAQ : https://github.com/square/leakcanary/wiki/FAQ
配置
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'
}
使用说明
建立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;