在 android 应用程序中使用 Facebook AccountKit 登录时内存泄漏

Memory leak while login with Facebook AccountKit in android app

我正在使用 Facebook 的 AccountKit(最新版本)通过短信进行用户登录。每当我单击登录时,LeakCanary 都会显示巨大的内存泄漏。我知道这是一个库问题,但有解决方法吗?

堆分析显示 11 个保留对象。转储后,应用程序大小增加了 200 MB。这是日志:

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

它只发生在调试版本中。发布应用程序后,内存泄漏问题得到解决。仍然不清楚为什么它会出现在调试版本中。