android - 我的应用程序在使用泄漏金丝雀时冻结 - 为什么?
问题描述
我正在开发一个使用 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 错误。请帮忙。
解决方案
您可能知道,LeakCanary 旨在检测应用程序中的内存泄漏。当它显示“正在转储内存。应用程序冻结。Brrrr”-消息时,这不是因为您设置了 LeakCanary 错误,而是因为 LeakCanary 正在按预期工作并检测到泄漏。
应用程序冻结是因为 LeakCanary 必须记录应用程序和内存中每个线程的当前状态,然后为您提供有关它检测到的泄漏的报告。
因此,您看到此消息意味着您的应用存在需要修复的内存泄漏。在“Leaks”-App、您的 logcat 输出或单击弹出的通知中检查您获得的泄漏报告。在那里,您应该找到有关泄漏内容的详细信息。
推荐阅读
- html - 如何在 R 中打印 HTML
- c# - 为什么 Jarray 添加重复的作业?
- c - 如果我们在 C 中的调用函数中不使用 return 语句会发生什么?
- c - 为什么只有在选择数组是3或7个元素时才发生分割故障?
- apache - 如何管理安装到 docker 容器中的卷的权限?
- css - Bootstrap 卡在图像周围有白色修剪
- eclipse - 日食 2019 03 和 TFS
- c - SDL 仅与 main 一起使用,而忽略了我程序中的其他 .c 和 .h 文件
- rest - 通过浏览器在 WADL 中调用休息服务
- debugging - 如何在运行时知道 Kony 应用程序是在调试模式还是发布模式下构建的