最近編輯於2017年12月26日
LeakCanary確實是一個檢測是否存在內存泄漏的好工具(PS:正常的Link檢測也可以)。
接入方式
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
}
public class ExampleApplication extends Application {
@Override public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);
// Normal app init code...
}
}
就是這麼簡單,更多參考
https://github.com/square/leakcanary
https://github.com/square/leakcanary/wiki/FAQ
最後,其實內存泄漏的問題,本身android studio自帶代碼檢測功能,如果代碼不規範上面就會有一層灰色,很多問題代碼提示都會給出解決方案。