[英]I am getting unknown memory leak whenever I am closing any fragment
I am making blog app and getting memory leak when ever I closing any fragment....I try to find answer and some says to null out your views reference on onDestroyView or onDestroy(I tried it both and it don't work) and than I just created blank fragment without any views(just a blue background ) and even if I am closing BlankFragment,still I am getting same memory leak...follow is the code I am using to add blank fragment我正在制作博客应用程序并在关闭任何片段时得到 memory 泄漏......我试图找到答案,有些人对 null 说你在 onDestroyView 或 onDestroy 上的意见参考(我都试过了,但它不起作用)和比我刚刚创建没有任何视图的空白片段(只是蓝色背景),即使我正在关闭 BlankFragment,我仍然得到相同的 memory 泄漏......下面是我用来添加空白片段的代码
Fragment blankFragment = new BlankFragment();
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.hide(userProfileFragment); //hiding userProfileFragment which is current fragment
transaction.add(R.id.frame_container, blankFragment,"blank");
transaction.addToBackStack(null);
transaction.commit();
and after I am closing just even a blankFragment which does not hold any views..I am getting the following memory leak warning in Leak Canary在我关闭一个没有任何意见的空白片段之后..我在 Leak Canary 中收到以下 memory 泄漏警告
┬───
│ GC Root: System class
│
├─ leakcanary.internal.InternalLeakCanary class
│ Leaking: NO (MainActivity↓ is not leaking and a class is never leaking)
│ ↓ static InternalLeakCanary.resumedActivity
├─ MainActivity instance
│ Leaking: NO (HomeFragment↓ is not leaking and Activity#mDestroyed is false)
│ ↓ MainActivity.startingFragment
├─ HomeFragment instance
│ Leaking: NO (UserProfile_Fragment↓ is not leaking and Fragment#mFragmentManager is not null)
│ Fragment.mTag=home
│ ↓ HomeFragment.mFragmentManager
├─ androidx.fragment.app.FragmentManagerImpl instance
│ Leaking: NO (UserProfile_Fragment↓ is not leaking)
│ ↓ FragmentManagerImpl.mAdded
├─ java.util.ArrayList instance
│ Leaking: NO (UserProfile_Fragment↓ is not leaking)
│ ↓ ArrayList.elementData
├─ java.lang.Object[] array
│ Leaking: NO (UserProfile_Fragment↓ is not leaking)
│ ↓ Object[].[3]
├─ UserProfile_Fragment instance
│ Leaking: NO (Fragment#mFragmentManager is not null)
│ Fragment.mTag=user
│ ↓ UserProfile_Fragment.transaction
│ ~~~~~~~~~~~
├─ androidx.fragment.app.BackStackRecord instance
│ Leaking: UNKNOWN
│ ↓ BackStackRecord.mOps
│ ~~~~
├─ java.util.ArrayList instance
│ Leaking: UNKNOWN
│ ↓ ArrayList.elementData
│ ~~~~~~~~~~~
├─ java.lang.Object[] array
│ Leaking: UNKNOWN
│ ↓ Object[].[1]
│ ~~~
├─ androidx.fragment.app.FragmentTransaction$Op instance
│ Leaking: UNKNOWN
│ ↓ FragmentTransaction$Op.mFragment
│ ~~~~~~~~~
╰→ BlankFragment instance Leaking: YES (ObjectWatcher was watching this because BlankFragment received Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
UserProfile_Fragment.transaction is the likely cause of the leak, you shouldn't hold the fragment transaction in memory as it keeps the BlankFragment. UserProfile_Fragment.transaction 可能是导致泄漏的原因,您不应将片段事务保存在 memory 中,因为它保留了 BlankFragment。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.