精选圈子榜单优站
跟我一起AI炒ETF
赚大钱赚大钱赚大钱

Android内存泄露工具Leakcanary的使用


GitHub地址

1、引入依赖

 dependencies {
   debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.2'
   releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.2'
 }

2.application中初始化

public static RefWatcher getRefWatcher(Context context) {
MyApplication application = (MyApplication) context.getApplicationContext();
return application.refWatcher;
}

private RefWatcher refWatcher;
oncreate方法中
private void initlLeakcanary() {
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);
}

3、在activity和fragment的onDestroy

//内存泄露监控
RefWatcher refWatcher = MyApplication.getRefWatcher(mContext);
refWatcher.watch(this);

Screenshot_2017-09-07-14-59-19-585_com

如上是handler的内存泄露


  • 若文章侵犯了您的权益,请联系站长处理:nemo@link-nemo.com

  • 2017-09-07
  • 2154阅读
评论