Android/OutOfMemory対策/leakcanary
提供: 初心者エンジニアの簡易メモ
leakcanaryを導入して調査
公式:https://github.com/square/leakcanary
導入方法
ver1と2がある。
何が違うかは、こちらを。https://square.github.io/leakcanary/upgrading-to-leakcanary-2.0/
ver1
app/build.gradle
dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
// Optional, if you use support library fragments:
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
}
ExampleApplication.java
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...
}
}
ver2
app/build.gradle
dependencies {
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
}
使い方
- インストールするとleakアプリが入る。
- サンプルアプリ内を色々触って、Activityのページを閉じ、onDestoryを実行する。
- leakアプリを開き、HeapDumpsタブのDumpHeapNowを選択する
- 上部お知らせのアイコンに進捗が出るので、完了するのを待つ。
- 結果はLeaksタブに出るので、確認する。
