android.support.constraint.ConstraintLayout 已经泄露: [英] android.support.constraint.ConstraintLayout has leaked:

查看:132
本文介绍了android.support.constraint.ConstraintLayout 已经泄露:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 LeakCanary 检测应用程序中的内存泄漏.我使用它成功识别并修复了一些泄漏,但我正在努力找到此泄漏的根源:

I'm using LeakCanary to detect memory leaks in an app. I successfully identified and fixed some leaks using it, but I am struggling find the root of this leak:

* android.support.constraint.ConstraintLayout has leaked:
* Toast$TN.mNextView
* ↳ LinearLayout.mContext
* ↳ HomeActivity.!(mDelegate)!
* ↳ AppCompatDelegateImplN.!(mActionBar)!
* ↳ ToolbarActionBar.!(mDecorToolbar)!
* ↳ ToolbarWidgetWrapper.!(mToolbar)!
* ↳ Toolbar.mParent
* ↳ ConstraintLayout
* Reference Key: 552b5bc5-409d-44c4-8412-87341237ae6d
* Device: samsung samsung SM-G960F starltexx
* Android Version: 8.0.0 API: 26 LeakCanary: 1.6.2 0ebc1fc
* Durations: watch=5769ms, gc=153ms, heap dump=933ms, analysis=5802ms

此泄漏是由 Android SDK 还是应用特定代码引起的?

Is this leak caused by the Android SDK or app specific code?

推荐答案

泄漏是由特定于应用程序的代码引起的.一个名为 getActivity().setSupportActionBar() 的片段,其视图包含在片段布局中.当切换到另一个片段时,资源无法被 gc'ed,因为 Activity 仍然持有对不再可见的工具栏的引用.我通过在片段 onDestroyView() 方法中调用 getActivity().setSupportActionBar(null) 修复了这个泄漏,该方法删除了对工具栏的引用.

The leak was caused by app specific code. One fragment called getActivity().setSupportActionBar() with a view contained in the fragments layout. When switching to another fragment the resources couldn't get gc'ed because the activity was still holding a reference to the no longer visible toolbar. I fixed this leak by calling getActivity().setSupportActionBar(null) in the fragments onDestroyView() method, which removes the reference to the toolbar.

这篇关于android.support.constraint.ConstraintLayout 已经泄露:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆