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

问题描述 投票:0回答:1

当我从活动中分离片段时,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)
memory-leaks android-architecture-components android-viewmodel leakcanary
1个回答
0
投票

MoreFragment在onDestroyView之后保留FragmentMoreBindingImpl(它本身包含NestedScrollView)。您应该在Fragment.onDestroyView()

中清除对绑定的引用
© www.soinside.com 2019 - 2024. All rights reserved.