「Android/OutOfMemory対策/leakcanary」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→ver2) |
|||
| 行38: | 行38: | ||
<pre> | <pre> | ||
dependencies { | dependencies { | ||
| − | + | debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4' | |
} | } | ||
</pre> | </pre> | ||
2020年9月18日 (金) 15:22時点における版
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'
}
使い方
メモリリークが起こると、自動で検知&解析してくれる。
