美文网首页
android . 内存泄露 LeakCanary 使用

android . 内存泄露 LeakCanary 使用

作者: MorningandSun | 来源:发表于2019-10-11 16:23 被阅读0次

1.build.gradle 添加

        debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1'
        releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
        // Optional, if you use support library fragments:
        debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1'

2.自定义application

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

3.在发生内存泄漏的地方会出现提示

image.png

4.结束后在模拟器上会出现一个


image.png

点击进去即可查看内存泄漏的地方。

相关文章

网友评论

      本文标题:android . 内存泄露 LeakCanary 使用

      本文链接:https://www.haomeiwen.com/subject/ffqxmctx.html