渝潼不肖生
  • 5
  • 新人请关照

databinding内存泄露

ApplicationLeak(className=android.widget.LinearLayout, leakTrace=
┬
├─ android.app.ActivityThread
│    Leaking: NO (ActivityThread↓ is not leaking and a class is never leaking)
│    GC Root: System class
│    ↓ static ActivityThread.sCurrentActivityThread
├─ android.app.ActivityThread
│    Leaking: NO (ArrayMap↓ is not leaking)
│    ↓ ActivityThread.mActivities
├─ android.util.ArrayMap
│    Leaking: NO (Object[]↓ is not leaking)
│    ↓ ArrayMap.mArray
├─ java.lang.Object[]
│    Leaking: NO (ActivityThread$ActivityClientRecord↓ is not leaking)
│    ↓ array Object[].[1]
├─ android.app.ActivityThread$ActivityClientRecord
│    Leaking: NO (MainActivity↓ is not leaking)
│    ↓ ActivityThread$ActivityClientRecord.activity
├─ com.ukex.module.index.ui.MainActivity
│    Leaking: NO (FragmentController↓ is not leaking and Activity#mDestroyed is false)
│    ↓ MainActivity.mFragments
├─ androidx.fragment.app.FragmentController
│    Leaking: NO (FragmentActivity$HostCallbacks↓ is not leaking)
│    ↓ FragmentController.mHost
├─ androidx.fragment.app.FragmentActivity$HostCallbacks
│    Leaking: NO (FragmentManagerImpl↓ is not leaking)
│    ↓ FragmentActivity$HostCallbacks.mFragmentManager
├─ androidx.fragment.app.FragmentManagerImpl
│    Leaking: NO (NavHostFragment↓ is not leaking)
│    ↓ FragmentManagerImpl.mPrimaryNav
├─ androidx.navigation.fragment.NavHostFragment
│    Leaking: NO (FragmentManagerImpl↓ is not leaking and Fragment#mFragmentManager is not null)
│    ↓ NavHostFragment.mChildFragmentManager
├─ androidx.fragment.app.FragmentManagerImpl
│    Leaking: NO (HashMap↓ is not leaking)
│    ↓ FragmentManagerImpl.mActive
├─ java.util.HashMap
│    Leaking: NO (HashMap$Node[]↓ is not leaking)
│    ↓ HashMap.table
├─ java.util.HashMap$Node[]
│    Leaking: NO (HashMap$Node↓ is not leaking)
│    ↓ array HashMap$Node[].[0]
├─ java.util.HashMap$Node
│    Leaking: NO (HomeFragment↓ is not leaking)
│    ↓ HashMap$Node.value
├─ com.ukex.module.index.ui.HomeFragment
│    Leaking: NO (Fragment#mFragmentManager is not null)
│    ↓ HomeFragment.dataBinding
│                   ~~~~~~~~~~~
├─ com.ukex.databinding.HomeFragmentBindingImpl
│    Leaking: UNKNOWN
│    ↓ HomeFragmentBindingImpl.mRoot
│                              ~~~~~
╰→ android.widget.LinearLayout
​     Leaking: YES (ObjectWatcher was watching this)
​     mContext instance of com.ukex.module.index.ui.MainActivity with mDestroyed = false
​     View#mParent is null
​     View#mAttachInfo is null (view detached)
​     View.mWindowAttachCount = 1
​     key = b7ad80c9-203d-416e-ba52-8d8b2edca920
​     watchDurationMillis = 17179
​     retainedDurationMillis = 12178
, retainedHeapByteSize=6367)
阅读 1.4k
评论
    1 个回答

    在onDestroyView 添加

    override fun onDestroyView() {
        super.onDestroyView()
        binding?.unbind()
        binding = null
    }

    binding 对象中有View的 引用..

    评论 赞赏
      撰写回答

      登录后参与交流、获取后续更新提醒