Kiwix-android: Memory leak in KiwixReaderFragment

Created on 11 Oct 2020  Β·  7Comments  Β·  Source: kiwix/kiwix-android

Describe the bug

KiwixReaderFragment is leaking

Expected behavior

No memory leaks should be present.

Steps to reproduce the behavior:

  1. Open the history fragment.
  2. Click a history item.
  3. Open the history fragment again.
  4. Close the history fragment.
  5. Minimize the app (go to the android home screen).

Screenshots

┬───
β”‚ GC Root: System class
β”‚
β”œβ”€ android.view.inputmethod.InputMethodManager class
β”‚    Leaking: NO (InputMethodManager↓ is not leaking and a class is never leaking)
β”‚    ↓ static InputMethodManager.sInstance
β”œβ”€ android.view.inputmethod.InputMethodManager instance
β”‚    Leaking: NO (DecorView↓ is not leaking and InputMethodManager is a singleton)
β”‚    ↓ InputMethodManager.mNextServedView
β”œβ”€ com.android.internal.policy.DecorView instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking and View attached)
β”‚    mContext instance of com.android.internal.policy.DecorContext, wrapping activity org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    Parent android.view.ViewRootImpl not a android.view.View
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mWindowAttachCount = 1
β”‚    ↓ DecorView.mAttachInfo
β”œβ”€ android.view.View$AttachInfo instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ View$AttachInfo.mScrollContainers
β”œβ”€ java.util.ArrayList instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ ArrayList.elementData
β”œβ”€ java.lang.Object[] array
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ Object[].[2]
β”œβ”€ androidx.recyclerview.widget.RecyclerView instance
β”‚    Leaking: NO (View attached)
β”‚    mContext instance of org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    View.parent android.widget.LinearLayout attached as well
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mID = R.id.right_drawer_list
β”‚    View.mWindowAttachCount = 1
β”‚    ↓ RecyclerView.mAdapter
β”‚                   ~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.TableDrawerAdapter instance
β”‚    Leaking: UNKNOWN
β”‚    ↓ TableDrawerAdapter.listener
β”‚                         ~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.CoreReaderFragment$7 instance
β”‚    Leaking: UNKNOWN
β”‚    Anonymous class implementing org.kiwix.kiwixmobile.core.main.TableDrawerAdapter$TableClickListener
β”‚    ↓ CoreReaderFragment$7.this$0
β”‚                           ~~~~
β•°β†’ org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment instance
​     Leaking: YES (ObjectWatcher was watching this because org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment received Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
​     key = b9dd5d25-5ae3-4c56-83d1-f3e2fdae4252
​     watchDurationMillis = 8963
​     retainedDurationMillis = 3963

METADATA

Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: OnePlus
LeakCanary version: 2.4
App process name: org.kiwix.kiwixmobile
Analysis duration: 10339 ms
bug

All 7 comments

Setting the tableDrawerAdapters listener to null semms to fix this leak, but another shows up:

┬───
β”‚ GC Root: System class
β”‚
β”œβ”€ android.view.inputmethod.InputMethodManager class
β”‚    Leaking: NO (InputMethodManager↓ is not leaking and a class is never leaking)
β”‚    ↓ static InputMethodManager.sInstance
β”œβ”€ android.view.inputmethod.InputMethodManager instance
β”‚    Leaking: NO (DecorView↓ is not leaking and InputMethodManager is a singleton)
β”‚    ↓ InputMethodManager.mNextServedView
β”œβ”€ com.android.internal.policy.DecorView instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking and View attached)
β”‚    mContext instance of com.android.internal.policy.DecorContext, wrapping activity org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    Parent android.view.ViewRootImpl not a android.view.View
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mWindowAttachCount = 1
β”‚    ↓ DecorView.mAttachInfo
β”œβ”€ android.view.View$AttachInfo instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ View$AttachInfo.mScrollContainers
β”œβ”€ java.util.ArrayList instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ ArrayList.elementData
β”œβ”€ java.lang.Object[] array
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ Object[].[2]
β”œβ”€ androidx.recyclerview.widget.RecyclerView instance
β”‚    Leaking: NO (RelativeLayout↓ is not leaking and View attached)
β”‚    mContext instance of org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    View.parent android.widget.LinearLayout attached as well
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mID = R.id.right_drawer_list
β”‚    View.mWindowAttachCount = 1
β”‚    ↓ RecyclerView.mChildren
β”œβ”€ android.view.View[] array
β”‚    Leaking: NO (RelativeLayout↓ is not leaking)
β”‚    ↓ View[].[0]
β”œβ”€ android.widget.RelativeLayout instance
β”‚    Leaking: NO (View attached)
β”‚    mContext instance of org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    View.parent androidx.recyclerview.widget.RecyclerView attached as well
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mWindowAttachCount = 3
β”‚    ↓ RelativeLayout.mListenerInfo
β”‚                     ~~~~~~~~~~~
β”œβ”€ android.view.View$ListenerInfo instance
β”‚    Leaking: UNKNOWN
β”‚    ↓ View$ListenerInfo.mOnClickListener
β”‚                        ~~~~~~~~~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.TableDrawerAdapter$sam$android_view_View_OnClickListener$0 instance
β”‚    Leaking: UNKNOWN
β”‚    Anonymous class implementing android.view.View$OnClickListener
β”‚    ↓ TableDrawerAdapter$sam$android_view_View_OnClickListener$0.function
β”‚                                                                 ~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.TableDrawerAdapter$onBindViewHolder$1 instance
β”‚    Leaking: UNKNOWN
β”‚    Anonymous subclass of kotlin.jvm.internal.FunctionReference
β”‚    ↓ TableDrawerAdapter$onBindViewHolder$1.receiver
β”‚                                            ~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.CoreReaderFragment$7 instance
β”‚    Leaking: UNKNOWN
β”‚    Anonymous class implementing org.kiwix.kiwixmobile.core.main.TableDrawerAdapter$TableClickListener
β”‚    ↓ CoreReaderFragment$7.this$0
β”‚                           ~~~~
β•°β†’ org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment instance
​     Leaking: YES (ObjectWatcher was watching this because org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment received Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
​     key = 5c2f320e-626c-420a-9d2f-22a8b2603781
​     watchDurationMillis = 15543
​     retainedDurationMillis = 10509

METADATA

Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: OnePlus
LeakCanary version: 2.4
App process name: org.kiwix.kiwixmobile
Analysis duration: 16812 ms

@Frans-Lukas Do you wanna work on this issue?

@gouri-panda I won't until next weekend so if you feel like doing it before then, go ahead.

@gouri-panda If you can fix it quickly this would be much appreciated, I believe nobody is comfortable with the idea of shipping 3.4.1 with known memoery leaks.

@gouri-panda I will be taking over this ticket in the interest of expediting it

@Frans-Lukas I cannot reproduce this issue using the repro steps. Can you reverify this leak on latest develop?

Still reproducible, could it be book specific?

┬───
β”‚ GC Root: System class
β”‚
β”œβ”€ android.view.inputmethod.InputMethodManager class
β”‚    Leaking: NO (InputMethodManager↓ is not leaking and a class is never leaking)
β”‚    ↓ static InputMethodManager.sInstance
β”œβ”€ android.view.inputmethod.InputMethodManager instance
β”‚    Leaking: NO (DecorView↓ is not leaking and InputMethodManager is a singleton)
β”‚    ↓ InputMethodManager.mNextServedView
β”œβ”€ com.android.internal.policy.DecorView instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking and View attached)
β”‚    mContext instance of com.android.internal.policy.DecorContext, wrapping activity org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    Parent android.view.ViewRootImpl not a android.view.View
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mWindowAttachCount = 1
β”‚    ↓ DecorView.mAttachInfo
β”œβ”€ android.view.View$AttachInfo instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ View$AttachInfo.mScrollContainers
β”œβ”€ java.util.ArrayList instance
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ ArrayList.elementData
β”œβ”€ java.lang.Object[] array
β”‚    Leaking: NO (RecyclerView↓ is not leaking)
β”‚    ↓ Object[].[2]
β”œβ”€ androidx.recyclerview.widget.RecyclerView instance
β”‚    Leaking: NO (View attached)
β”‚    mContext instance of org.kiwix.kiwixmobile.main.KiwixMainActivity with mDestroyed = false
β”‚    View.parent android.widget.LinearLayout attached as well
β”‚    View#mParent is set
β”‚    View#mAttachInfo is not null (view attached)
β”‚    View.mID = R.id.right_drawer_list
β”‚    View.mWindowAttachCount = 1
β”‚    ↓ RecyclerView.mAdapter
β”‚                   ~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.TableDrawerAdapter instance
β”‚    Leaking: UNKNOWN
β”‚    ↓ TableDrawerAdapter.listener
β”‚                         ~~~~~~
β”œβ”€ org.kiwix.kiwixmobile.core.main.CoreReaderFragment$7 instance
β”‚    Leaking: UNKNOWN
β”‚    Anonymous class implementing org.kiwix.kiwixmobile.core.main.TableDrawerAdapter$TableClickListener
β”‚    ↓ CoreReaderFragment$7.this$0
β”‚                           ~~~~
β•°β†’ org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment instance
​     Leaking: YES (ObjectWatcher was watching this because org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment received Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
​     key = e2d4fa0d-7fad-4970-9cb9-09cd05c6c623
​     watchDurationMillis = 6936
​     retainedDurationMillis = 1915

METADATA

Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: OnePlus
LeakCanary version: 2.4
App process name: org.kiwix.kiwixmobile
Analysis duration: 10368 ms
Was this page helpful?
0 / 5 - 0 ratings