泄漏金丝雀在分离碎片上检测到一些内存泄漏



当我从活动中分离片段时,Leak Canary在androidx.core.widget.NestedScrollView中检测到一些内存泄漏。我在其中没有可观察到的内容,只有一个绑定到其数据绑定对象的视图模型。

ApplicationLeak(className=androidx.core.widget.NestedScrollView, leakTrace=
┬
.
.
.
│    ↓ MainActivity.controller
├─ com.ncapdevi.fragnav.FragNavController
│    Leaking: NO (ArrayList↓ is not leaking)
│    ↓ FragNavController.rootFragments
├─ java.util.ArrayList
│    Leaking: NO (Object[]↓ is not leaking)
│    ↓ ArrayList.elementData
├─ java.lang.Object[]
│    Leaking: NO (MoreFragment↓ is not leaking)
│    ↓ array Object[].[3]
├─ my.package.name.ui.main.more.MoreFragment
│    Leaking: NO (Fragment#mFragmentManager is not null)
│    Fragment.mTag=my.package.name.ui.main.more.MoreFragment4
│    ↓ MoreFragment.binding
│                   ~~~~~~~
├─ my.package.name.databinding.FragmentMoreBindingImpl
│    Leaking: UNKNOWN
│    ↓ FragmentMoreBindingImpl.mRoot
│                              ~~~~~
╰→ androidx.core.widget.NestedScrollView
Leaking: YES (ObjectWatcher was watching this)
mContext instance of my.package.name.ui.main.MainActivity with mDestroyed = false
View#mParent is null
View#mAttachInfo is null (view detached)
View.mWindowAttachCount = 1
key = 2262922d-06f8-4abb-ba7b-d276c6fe3082
watchDurationMillis = 1910
retainedDurationMillis = -1
, retainedHeapByteSize=7132)

MoreFragment在onDestroyView之后保留FragmentMoreBindingImpl(它本身包含NestedScrollView(。您应该清除Fragment.onDestroyView((中对绑定的引用

最新更新