1.在工程gradle加上后面2句
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' }
2.在自己定义的application这样写
public void onCreate() { super.onCreate();3.在activity的ondestory里面这样写if (LeakCanary.isInAnalyzerProcess(this)) { // This process is dedicated to LeakCanary for heap analysis. // You should not init your app in this process. return; }refWatcher = LeakCanary.install(this);}public static RefWatcher getRefWatcher(Context context) { MApplication application = (MApplication) context.getApplicationContext(); return application.refWatcher;}private RefWatcher refWatcher;
@Override protected void onDestroy() { super.onDestroy(); RefWatcher refWatcher = MApplication.getRefWatcher(this); refWatcher.watch(this); }eclipse 看这里:
http://blog.csdn.net/liudehuaii18/article/details/46287695