Android ViewRootImpl 上下文泄漏问题

标签 android memory-leaks leakcanary

嗨,我正在为我的应用程序进行内存分析。为此,我正在尝试识别我的应用程序的内存泄漏。我得到以下类型的内存泄漏。

com.sample.activityname has leaked:
* static WindowManagerGlobal.sDefaultWindowManager
* ↳ WindowManagerGlobal.mRoots
* ↳ ArrayList.elementData
* ↳ array Object[].[4]
* ↳ **ViewRootImpl.!(mContext)!**
* ↳ **ContextThemeWrapper.!(mBase)!**
* ↳ activityname

的可能原因是什么? ViewRootImpl.mContext 泄漏。我正在使用leakcanary 来识别我的泄漏。我也已经通过https://github.com/square/leakcanary/issues/94 .但无法得到任何提示。

最佳答案

我注意到我的应用程序中存在内存泄漏,其中堆转储看起来就像你的一样。我最终将此追溯到我对 ProgressDialog 的使用。类(class)。我的一些 Activity 会使用 ProgressDialog.show() 显示进度对话框。但会调用 finish()在我调用 dismiss() 之前在显示的进度对话框中。
也许您正在显示某种类型的 ProgressDialog、AlertDialog 或 Dialog 在销毁 Activity 之前没有被关闭?希望这会有所帮助!

关于Android ViewRootImpl 上下文泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55354006/

相关文章:

android - 如何在 Android 4.3 api 18 上更改 ActionBar 标题文本的颜色

android - 在 ListView 适配器内的 setOnEditorActionListener 中传递多个值

单击特定应用程序图标时 Android 启动应用程序

在循环中调用 pthread_cancel() 显示内存使用量增加

android - MapView v2 保持上下文

android - 更改太多布局的可见性可能会导致性能问题吗?

android - 找不到资源样式/LaunchTheme

delphi - Delphi/DBExpress 的内存泄漏

javascript - 为什么对象在被 document.getElementById 编辑后必须为 IE 清空?

android - LeakCanary 如何仅通过添加依赖项来安装和准备就绪?