在build.gradle文件添加引用
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.2'
然后在初始化Application的时候做初始化
//在Application的onCreate方法中调用初始化方法
protected RefWatcher setupLeakCanary()
{
if (LeakCanary.isInAnalyzerProcess(this))
{
return RefWatcher.DISABLED;
}
return LeakCanary.install(this);
}