51Testing软件测试论坛

标题: 引入LeakCanary监听内存泄漏 [打印本页]

作者: 感悟时分    时间: 2019-3-15 13:45
标题: 引入LeakCanary监听内存泄漏
  1. debugCompile ‘com.squareup.leakcanary:leakcanary-android:1.5.4’
  2. releaseCompile ‘com.squareup.leakcanary:leakcanary-android-no-op:1.5.4’二在application里添加public class TestApplication extends Application {
  3.     @Override
  4.     public void onCreate() {
  5.         super.onCreate();
  6.         initLeakCanary();
  7.     }

  8.     private RefWatcher mRefWatcher;

  9.     private void initLeakCanary() {

  10.         if (LeakCanary.isInAnalyzerProcess(this)) {
  11.             // This process is dedicated to LeakCanary for heap analysis.
  12.             // You should not init your app in this process.
  13.             mRefWatcher = RefWatcher.DISABLED;
  14.             return;
  15.         }
  16.         mRefWatcher = LeakCanary.install(this);
  17.     }
  18. }
复制代码







欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2