leakcanary icon indicating copy to clipboard operation
leakcanary copied to clipboard

Leak in ViewGroup using Drag listener

Open raymadigan opened this issue 5 years ago • 5 comments

LeakTrace information

Using LeakCanary 2.5 on API 29

When the drag finishes the system will report: W/System: A resource failed to call release. When the drop does nothing in the ACTION_DROP case, the above message is still generated When the drop is outside of the drag listener the message is still generated.

1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
19039 bytes retained by leaking objects
Signature: b424ce7d216e2ffd7a88b4fc69f57fd45317339
┬───
│ 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.mCurRootView
├─ com.android.internal.policy.DecorView instance
│    Leaking: NO (LinearLayout↓ is not leaking and View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mWindowAttachCount = 1
│    mContext instance of com.android.internal.policy.DecorContext, wrapping activity com.salinas.draganddrop.
│    MainActivity with mDestroyed = false
│    ↓ DecorView.mContentRoot
├─ android.widget.LinearLayout instance
│    Leaking: NO (FrameLayout↓ is not leaking and View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mWindowAttachCount = 1
│    mContext instance of com.salinas.draganddrop.MainActivity with mDestroyed = false
│    ↓ LinearLayout.mCurrentDragChild
├─ android.widget.FrameLayout instance
│    Leaking: NO (ActionBarOverlayLayout↓ is not leaking and View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mWindowAttachCount = 1
│    mContext instance of com.salinas.draganddrop.MainActivity with mDestroyed = false
│    ↓ FrameLayout.mCurrentDragChild
├─ androidx.appcompat.widget.ActionBarOverlayLayout instance
│    Leaking: NO (ContentFrameLayout↓ is not leaking and View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mID = R.id.decor_content_parent
│    View.mWindowAttachCount = 1
│    mContext instance of androidx.appcompat.view.ContextThemeWrapper, wrapping activity com.salinas.draganddrop.
│    MainActivity with mDestroyed = false
│    ↓ ActionBarOverlayLayout.mContent
├─ androidx.appcompat.widget.ContentFrameLayout instance
│    Leaking: NO (GridLayout↓ is not leaking and View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mID = R.id.null
│    View.mWindowAttachCount = 1
│    mContext instance of androidx.appcompat.view.ContextThemeWrapper, wrapping activity com.salinas.draganddrop.
│    MainActivity with mDestroyed = false
│    ↓ ContentFrameLayout.mCurrentDragChild
├─ android.widget.GridLayout instance
│    Leaking: NO (FragmentContainerView↓ is not leaking and View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mWindowAttachCount = 1
│    mContext instance of com.salinas.draganddrop.MainActivity with mDestroyed = false
│    ↓ GridLayout.mCurrentDragChild
├─ androidx.fragment.app.FragmentContainerView instance
│    Leaking: NO (View attached)
│    View is part of a window view hierarchy
│    View.mAttachInfo is not null (view attached)
│    View.mID = R.id.nav_host_fragment
│    View.mWindowAttachCount = 1
│    mContext instance of com.salinas.draganddrop.MainActivity with mDestroyed = false
│    ↓ FragmentContainerView.mCurrentDragChild
│                            ~~~~~~~~~~~~~~~~~
╰→ android.widget.GridLayout instance
     Leaking: YES (ObjectWatcher was watching this because com.salinas.draganddrop.DropAndDragPage received
     Fragment#onDestroyView() callback (references to its views should be cleared to prevent leaks))
     Retaining 19039 bytes in 410 objects
     key = f8889254-01eb-4ce2-8073-82c3a8da77f1
     watchDurationMillis = 575550
     retainedDurationMillis = 570544
     View not part of a window view hierarchy
     View.mAttachInfo is null (view detached)
     View.mWindowAttachCount = 1
     mContext instance of com.salinas.draganddrop.MainActivity with mDestroyed = false
 ====================================

raymadigan avatar Oct 06 '20 17:10 raymadigan

FragmentContainerView is a ViewGroup and ViewGroup.mCurrentDragChild is the field holding a reference to the detached object.

If you can reproduce this with a sample project, you should file a bug, either to Android X or AOSP.

pyricau avatar Oct 07 '20 03:10 pyricau

Any update?

pyricau avatar Dec 07 '20 19:12 pyricau

I reported it as a bug and haven't heard back.

raymadigan avatar Dec 07 '20 19:12 raymadigan

Can you share the link?

pyricau avatar Dec 07 '20 19:12 pyricau

https://issuetracker.google.com/issues/170276524

raymadigan avatar Dec 07 '20 20:12 raymadigan

Going forward this leak will be reported by LeakCanary as a known library leak.

pyricau avatar Nov 09 '22 21:11 pyricau