android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.44k stars 8.28k forks source link

[NavigationAdvancedSample] memory leak #899

Open Morteza-Rastgoo opened 4 years ago

Morteza-Rastgoo commented 4 years ago

I use NavigationAdvancedSample code in a fragment instead of activity and attach LeakCanary.

        val navGraphIds = listOf(
            R.navigation.nav_invoice,
            R.navigation.nav_transfer,
            R.navigation.nav_shop,
            R.navigation.nav_card,
            R.navigation.nav_settings
        )

        // Setup the bottom navigation view with a list of navigation graphs
        currentNavController = binding.bottomNavView.setupWithNavController(
            navGraphIds = navGraphIds,
            fragmentManager = childFragmentManager,
            containerId = R.id.navHostMain,
            intent = requireActivity().intent
        )

It detects this leak which I assume it is different with this issue


   D/LeakCanary: Signature: c7148cbfdf14c8a854bcc1587e86bcf51bbc2
           D/LeakCanary: ┬───
   D/LeakCanary: │ GC Root: System class
   D/LeakCanary: │
   D/LeakCanary: ├─ android.app.ActivityThread class
   D/LeakCanary: │    Leaking: NO (BaseActivity↓ is not leaking and a class is never leaking)
   D/LeakCanary: │    ↓ static ActivityThread.sCurrentActivityThread
           D/LeakCanary: ├─ android.app.ActivityThread instance
           D/LeakCanary: │    Leaking: NO (BaseActivity↓ is not leaking)
   D/LeakCanary: │    ↓ ActivityThread.mTopActivityClient
   D/LeakCanary: ├─ android.app.ActivityThread$ActivityClientRecord instance
   D/LeakCanary: │    Leaking: NO (BaseActivity↓ is not leaking)
   D/LeakCanary: │    ↓ ActivityThread$ActivityClientRecord.activity
   D/LeakCanary: ├─ com.examplee.presentation.base.BaseActivity instance
           D/LeakCanary: │    Leaking: NO (Activity#mDestroyed is false)
   D/LeakCanary: │    ↓ BaseActivity.mOnBackPressedDispatcher
   D/LeakCanary: │                   ~~~~~~~~~~~~~~~~~~~~~~~~
   D/LeakCanary: ├─ androidx.activity.OnBackPressedDispatcher instance
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    ↓ OnBackPressedDispatcher.mOnBackPressedCallbacks
   D/LeakCanary: │                              ~~~~~~~~~~~~~~~~~~~~~~~
   D/LeakCanary: ├─ java.util.ArrayDeque instance
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    ↓ ArrayDeque.elements
   D/LeakCanary: │                 ~~~~~~~~
   D/LeakCanary: ├─ java.lang.Object[] array
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    ↓ Object[].[6]
   D/LeakCanary: │               ~~~
   D/LeakCanary: ├─ androidx.fragment.app.FragmentManager$1 instance
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    Anonymous subclass of androidx.activity.OnBackPressedCallback
           D/LeakCanary: │    ↓ FragmentManager$1.this$0
   D/LeakCanary: │                        ~~~~~~
   D/LeakCanary: ├─ androidx.fragment.app.FragmentManagerImpl instance
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    ↓ FragmentManagerImpl.mBackStackChangeListeners
   D/LeakCanary: │                          ~~~~~~~~~~~~~~~~~~~~~~~~~
   D/LeakCanary: ├─ java.util.ArrayList instance
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    ↓ ArrayList.elementData
   D/LeakCanary: │                ~~~~~~~~~~~
   D/LeakCanary: ├─ java.lang.Object[] array
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    ↓ Object[].[0]
   D/LeakCanary: │               ~~~
   D/LeakCanary: ├─ com.examplee.util.extensions.NavigationExtensionsKt$setupWithNavController$3 instance
           D/LeakCanary: │    Leaking: UNKNOWN
   D/LeakCanary: │    Anonymous class implementing androidx.fragment.app.FragmentManager$OnBackStackChangedListener
   D/LeakCanary: │    ↓ NavigationExtensionsKt$setupWithNavController$3.$this_setupWithNavController
   D/LeakCanary: │                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   D/LeakCanary: ├─ com.google.android.material.bottomnavigation.BottomNavigationView instance
           D/LeakCanary: │    Leaking: YES (View detached and has parent)
   D/LeakCanary: │    mContext instance of com.examplee.presentation.base.BaseActivity with mDestroyed = false
   D/LeakCanary: │    View#mParent is set
   D/LeakCanary: │    View#mAttachInfo is null (view detached)
   D/LeakCanary: │    View.mID = R.id.bottomNavView
   D/LeakCanary: │    View.mWindowAttachCount = 1
   D/LeakCanary: │    ↓ BottomNavigationView.mParent
   D/LeakCanary: ╰→ androidx.appcompat.widget.LinearLayoutCompat instance
           D/LeakCanary: ​     Leaking: YES (ObjectWatcher was watching this because com.examplee.presentation.main.MainFragment received Fragment#onDestroyView() callback (references to its views should be cleared to prevent leaks))
   D/LeakCanary: ​     key = f9688e70-4e8a-4832-8175-90dc62ed94a1
           D/LeakCanary: ​     watchDurationMillis = 4681
   D/LeakCanary: ​     retainedDurationMillis = -594
   D/LeakCanary: ​     mContext instance of com.examplee.presentation.base.BaseActivity with mDestroyed = false
   D/LeakCanary: ​     View#mParent is null
   D/LeakCanary: ​     View#mAttachInfo is null (view detached)
   D/LeakCanary: ​     View.mWindowAttachCount = 1
   D/LeakCanary: 353330 bytes retained by leaking objects