I'm using AccountKit (latest version) by Facebook for user login with sms. Whenever I click on login, there's a huge memory leak shown by LeakCanary
. I know that its a library problem but is there a workaround?
Heap Analysis shows 11 retaining objects. After dumping, the app size grows by 200 MB. Here are the logs:
D/LeakCanary: HeapAnalysisSuccess(heapDumpFile=/data/user/0/com.sezy.coupons.offers/files/leakcanary/2019-08-03_18-58-49_213.hprof, createdAtTimeMillis=1564838992049, analysisDurationMillis=58428, applicationLeaks=[ApplicationLeak(className=com.facebook.accountkit.ui.StaticContentFragmentFactory$StaticContentFragment, leakTrace=
┬
├─ android.view.inputmethod.InputMethodManager
│ Leaking: NO (InputMethodManager↓ is not leaking and a class is never leaking)
│ GC Root: System class
│ ↓ static InputMethodManager.sInstance
├─ android.view.inputmethod.InputMethodManager
│ Leaking: NO (NotifyingEditText↓ is not leaking and InputMethodManager is a singleton)
│ ↓ InputMethodManager.mNextServedView
├─ com.facebook.accountkit.ui.NotifyingEditText
│ Leaking: NO (AccountKitActivity↓ is not leaking and View attached)
│ mContext instance of com.facebook.accountkit.ui.AccountKitActivity with mDestroyed = false
│ View.parent com.facebook.accountkit.ui.ConstrainedLinearLayout attached as well
│ View#mParent is set
│ View#mAttachInfo is not null (view attached)
│ View.mWindowAttachCount = 1
│ ↓ NotifyingEditText.mContext
├─ com.facebook.accountkit.ui.AccountKitActivity
│ Leaking: NO (Activity#mDestroyed is false)
│ ↓ AccountKitActivity.stateStackManager
│ ~~~~~~~~~~~~~~~~~
├─ com.facebook.accountkit.ui.StateStackManager
│ Leaking: UNKNOWN
│ ↓ StateStackManager.contentControllerMap
│ ~~~~~~~~~~~~~~~~~~~~
├─ java.util.HashMap
│ Leaking: UNKNOWN
│ ↓ HashMap.table
│ ~~~~~
├─ java.util.HashMap$Node[]
D/LeakCanary: │ Leaking: UNKNOWN
│ ↓ array HashMap$Node[].[1]
│ ~~~
├─ java.util.HashMap$Node
│ Leaking: UNKNOWN
│ ↓ HashMap$Node.value
│ ~~~~~
├─ com.facebook.accountkit.ui.PhoneSentCodeContentController
│ Leaking: UNKNOWN
│ ↓ PhoneSentCodeContentController.bottomFragment
│ ~~~~~~~~~~~~~~
╰→ com.facebook.accountkit.ui.StaticContentFragmentFactory$StaticContentFragment
Leaking: YES (Fragment#mFragmentManager is null and ObjectWatcher was watching this)
key = 23fcd5f7-e608-415a-92b8-404f7a807147
watchDurationMillis = 2123
retainedDurationMillis = -1
, retainedHeapByteSize=222), ApplicationLeak(className=com.facebook.accountkit.ui.StaticContentFragmentFactory$StaticContentFragment, leakTrace=
┬
├─ android.view.inputmethod.InputMethodManager
│ Leaking: NO (InputMethodManager↓ is not leaking and a class is never leaking)
│ GC Root: System class
│ ↓ static InputMethodManager.sInstance
├─ android.view.inputmethod.InputMethodManager
│ Leaking: NO (NotifyingEditText↓ is not leaking and InputMethodManager is a singleton)
│ ↓ InputMethodManager.mNextServedView
├─ com.facebook.accountkit.ui.NotifyingEditText
│ Leaking: NO (AccountKitActivity↓ is not leaking and View attached)
│ mContext instance of com.facebook.accountkit.ui.AccountKitActivity with mDestroyed = false
│ View.parent com.facebook.accountkit.ui.ConstrainedLinearLayout attached as well
│ View#mParent is set
│ View#mAttachInfo is not null (view attached)
│ View.mWindowAttachCount = 1
│ ↓ NotifyingEditText.mContext
├─ com.facebook.accountkit.ui.AccountKitActivity
│ Leaking: NO (Activity#mDestroyed is false)
│ ↓ AccountKitActivity.stateStackManager
│ ~~~~~~~~~~~~~~~~~
├─ com.facebook.accountkit.ui.StateStackManager
│ Leaking: UNKNOWN
│ ↓ StateStackManager.contentControllerMap
│ ~~~~~~~~~~~~~~~~~~~~
├─ java.util.HashMap
│ Leaking: UNKNOWN
D/LeakCanary: │ ↓ HashMap.table
│ ~~~~~
├─ java.util.HashMap$Node[]
│ Leaking: UNKNOWN
│ ↓ array HashMap$Node[].[1]
│ ~~~
├─ java.util.HashMap$Node
│ Leaking: UNKNOWN
│ ↓ HashMap$Node.value
│ ~~~~~
├─ com.facebook.accountkit.ui.PhoneSentCodeContentController
│ Leaking: UNKNOWN
│ ↓ PhoneSentCodeContentController.textFragment
│ ~~~~~~~~~~~~
╰→ com.facebook.accountkit.ui.StaticContentFragmentFactory$StaticContentFragment
Leaking: YES (Fragment#mFragmentManager is null and ObjectWatcher was watching this)
key = 9769d620-1366-4a2a-b79f-35bbbaa47252
watchDurationMillis = 2124
retainedDurationMillis = -1
, retainedHeapByteSize=222), ApplicationLeak(className=com.facebook.accountkit.ui.StaticContentFragmentFactory$StaticContentFragment, leakTrace=
┬
├─ android.view.inputmethod.InputMethodManager
│ Leaking: NO (InputMethodManager↓ is not leaking and a class is never leaking)
│ GC Root: System class
│ ↓ static InputMethodManager.sInstance
├─ android.view.inputmethod.InputMethodManager
│ Leaking: NO (NotifyingEditText↓ is not leaking and InputMethodManager is a singleton)
│ ↓ InputMethodManager.mNextServedView
├─ com.facebook.accountkit.ui.NotifyingEditText
│ Leaking: NO (AccountKitActivity↓ is not leaking and View attached)
│ mContext instance of com.facebook.accountkit.ui.AccountKitActivity with mDestroyed = false
│ View.parent com.facebook.accountkit.ui.ConstrainedLinearLayout attached as well
│ View#mParent is set
│ View#mAttachInfo is not null (view attached)
│ View.mWindowAttachCount = 1
│ ↓ NotifyingEditText.mContext
├─ com.facebook.accountkit.ui.AccountKitActivity
│ Leaking: NO (Activity#mDestroyed is false)
│ ↓ AccountKitActivity.stateStackManager
│ ~~~~~~~~~~~~~~~~~
├─ com.facebook.accountkit.ui.StateStackManager
│ Leaking: UNKNOWN
It was happening only in debug build. After publishing the app the memory leak problem got solved. Still unclear why it would occur in debug build.