首页 > 解决方案 > 我的应用程序在使用泄漏金丝雀时冻结 - 为什么?

问题描述

我正在开发一个使用 Leak Canary 库的 Android TV 应用程序,但问题是,当我在一段时间后使用我的应用程序时,它会显示一个错误“Dumping Memory. App Freezes. Brrrr”。我在谷歌上搜索了任何建议,但仍然出现错误。

在清单中,我提供了写入和读取存储的权限。

应用类代码:

     public class App extends Application {

private RefWatcher refWatcher;

public static RefWatcher getRefWatcher(Context context) {
    App application = (App) context.getApplicationContext();
    return application.refWatcher;
}

@Override
public void onCreate() {
    super.onCreate();
    refWatcher = LeakCanary.install(this);

}

在我的 Activity 和 Fragments 中,我在 OnDestroy() 中使用了 RefWatcher。方法。

IE

        @Override
protected void onDestroy() {

    if (timer != null) {
        timer.cancel();
        timer = null;
    }
    if (handler != null)
        handler.removeCallbacks(Update);
    super.onDestroy();


    RefWatcher refWatcher = App.getRefWatcher(this);
    refWatcher.watch(this);
}

但我仍然收到 Dumping Memory 错误。请帮忙。

标签: androidandroid-layoutmemoryleakcanary

解决方案


您可能知道,LeakCanary 旨在检测应用程序中的内存泄漏。当它显示“正在转储内存。应用程序冻结。Brrrr”-消息时,这不是因为您设置了 LeakCanary 错误,而是因为 LeakCanary 正在按预期工作并检测到泄漏。

应用程序冻结是因为 LeakCanary 必须记录应用程序和内存中每个线程的当前状态,然后为您提供有关它检测到的泄漏的报告。

因此,您看到此消息意味着您的应用存在需要修复的内存泄漏。在“Leaks”-App、您的 logcat 输出或单击弹出的通知中检查您获得的泄漏报告。在那里,您应该找到有关泄漏内容的详细信息。


推荐阅读