facebook twitter hatena line email

「Android/OutOfMemory対策/leakcanary」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ver2)
(使い方)
行43: 行43:
  
 
==使い方==
 
==使い方==
メモリリークが起こると、自動で検知&解析してくれる。
+
#インストールするとleakアプリが入る。
 +
#サンプルアプリ内を色々触って
 +
#leakアプリを開き、HeapDumpsタブのDumpHeapNowを選択する
 +
#上部お知らせのアイコンに進捗が出るので、完了するのを待つ。
 +
#結果はLeaksタブに出るので、確認する。
 +
 
 
==参考==
 
==参考==
 
https://mokumokulog.netlify.app/tech/20171112160128
 
https://mokumokulog.netlify.app/tech/20171112160128

2020年9月18日 (金) 15:28時点における版

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'
}

使い方

  1. インストールするとleakアプリが入る。
  2. サンプルアプリ内を色々触って
  3. leakアプリを開き、HeapDumpsタブのDumpHeapNowを選択する
  4. 上部お知らせのアイコンに進捗が出るので、完了するのを待つ。
  5. 結果はLeaksタブに出るので、確認する。

参考

https://mokumokulog.netlify.app/tech/20171112160128