以下是Leakcanary SDK提供的泄漏说明。从下面的行无法检测到我必须在哪一行进行更改以使代码可行,因为描述仅给出了类名,而没有给出特定的代码。
ApplicationLeak(className=com.pilotflyingj.plugin.a_android.ui.component.loyalty.RewardFragment, 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 (DecorView↓ is not leaking and InputMethodManager is a singleton)
│ ↓ InputMethodManager.mNextServedView
├─ com.android.internal.policy.DecorView
│ Leaking: NO (View attached)
│ mContext instance of com.android.internal.policy.DecorContext, wrapping activity com.pilotflyingj.plugin.a_android.ui.component.main.MainFrameActivity 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
│ Leaking: UNKNOWN
│ ↓ View$AttachInfo.mTreeObserver
│ ~~~~~~~~~~~~~
├─ android.view.ViewTreeObserver
│ Leaking: UNKNOWN
│ ↓ ViewTreeObserver.mOnScrollChangedListeners
│ ~~~~~~~~~~~~~~~~~~~~~~~~~
├─ android.view.ViewTreeObserver$CopyOnWriteArray
│ Leaking: UNKNOWN
│ ↓ ViewTreeObserver$CopyOnWriteArray.mData
│ ~~~~~
├─ java.util.ArrayList
│ Leaking: UNKNOWN
│ ↓ ArrayList.elementData
│ ~~~~~~~~~~~
├─ java.lang.Object[]
│ Leaking: UNKNOWN
│ ↓ array Object[].[2]
│ ~~~
├─ com.pilotflyingj.plugin.a_android.ui.component.loyalty.-$$Lambda$RewardFragment$-e5xQ8M432-uGOrhL3ajFrvOVQg
│ Leaking: UNKNOWN
│ ↓ -$$Lambda$RewardFragment$-e5xQ8M432-uGOrhL3ajFrvOVQg.f$0
│ ~~~
╰→ com.pilotflyingj.plugin.a_android.ui.component.loyalty.RewardFragment
Leaking: YES (Fragment#mFragmentManager is null and ObjectWatcher was watching this)
key = 11be43e3-0bcf-42fb-a087-025e52576844
watchDurationMillis = 8225
retainedDurationMillis = 3220
, retainedHeapByteSize=8730107)```
How to detech exact line of leak in class. Above is the leak description provided by leakcanary sdk.
答案 0 :(得分:0)
打开com.pilotflyingj.plugin.a_android.ui.component.loyalty.RewardFragment类,然后查找ViewTreeObserver.OnScrollChangedListener的实现。
发生泄漏是因为RewardFragment在ViewTreeObserver上设置了一个OnScrollChangedListener,但在该片段被销毁时并未将其删除。