gpt4 book ai didi

android - LeakCanary 不会捕获我故意添加的泄漏。我错过了什么?

转载 作者:太空狗 更新时间:2023-10-29 13:56:57 25 4
gpt4 key购买 nike

我们集成了 LeakCanary 来帮助我们解决我们认为是内存泄漏的问题。为了确保我们的每件事都设置正确,我创建了一个不会被删除的静态引用,并告诉 leakCanary 观看它,

public class Cat {
}

public class Box {
public Cat hiddenCat;
}

public class Docker {
public static Box container;
}

MainActivity

    Box box;
Cat schrod;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

box = new Box();
schrod = new Cat();
box.hiddenCat = schrod;
Docker.container = box;
Application.getRefWatcher().watch(schrod);


System.gc();
}

应用类中

    private static RefWatcher sRefWatcher;

@Override
public void onCreate() {
sRefWatcher = LeakCanary.install(this);
}
public static RefWatcher getRefWatcher() {
return sRefWatcher;
}

build.gradle 文件中:

 dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}

我错过了什么,它从未通知我对 schrod 对象的引用一直存在?

最佳答案

您可能需要将 build.gradle 依赖项更新到最新版本(可在本页的 Getting Started 指南中找到:https://github.com/square/leakcanary)恰好是:

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'

关于android - LeakCanary 不会捕获我故意添加的泄漏。我错过了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38731322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com