【问题标题】:How to find a Android Memory Leak如何查找 Android 内存泄漏
【发布时间】:2016-04-08 13:12:36
【问题描述】:

目前,我阅读了一些关于 Android 中可能存在的内存泄漏的书籍。但是,是否有任何方法(工具/技术)来检测内存泄漏而不是使用经验。

【问题讨论】:

    标签: android memory-leaks


    【解决方案1】:

    您可以使用LeakCanary 来检测内存泄漏

    将 LeakCanary 添加到您的项目中

    在你的build.gradle

    dependencies {
      debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
      releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
      testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
    }
    

    在您的Application 班级中:

    public class ExampleApplication extends Application {
      @Override public void onCreate() {
        super.onCreate();
        LeakCanary.install(this);
      }
    }
    

    在你的Manifest.xml

    <application
        android:name=".ExampleApplication"
    

    【讨论】:

      【解决方案2】:

      您可以尝试为此使用LeakCanary。这是一个有用的工具,而且设置起来相当简单:

      开始

      在你的build.gradle

      dependencies {
        debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
        releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
        testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
      }
      

      在您的Application 班级中:

      public class ExampleApplication extends Application {
        @Override public void onCreate() {
          super.onCreate();
          LeakCanary.install(this);
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2017-07-31
        • 1970-01-01
        • 2019-08-20
        • 2014-03-26
        • 2017-11-29
        • 1970-01-01
        相关资源
        最近更新 更多