Skip to content

blitz leaking TextView context that it is attached to even after cancelTimeAgoUpdates() #12

Description

@wax911

Describe the bug
Seems like blitz leaks the view that is attached to, here's a heap dump of the issue:

┬───
│ GC Root: Input or output parameters in native code
│
├─ android.os.MessageQueue instance
│    Leaking: NO (MessageQueue#mQuitting is false)
│    ↓ MessageQueue.mMessages
│                   ~~~~~~~~~
├─ android.os.Message instance
│    Leaking: UNKNOWN
│    ↓ Message.next
│              ~~~~
├─ android.os.Message instance
│    Leaking: UNKNOWN
│    ↓ Message.callback
│              ~~~~~~~~
├─ com.perfomer.blitz.BlitzAttachListener$runnable$1 instance
│    Leaking: UNKNOWN
│    Anonymous class implementing java.lang.Runnable
│    ↓ BlitzAttachListener$runnable$1.this$0~~~~~~
├─ com.perfomer.blitz.BlitzAttachListener instance
│    Leaking: UNKNOWN
│    ↓ BlitzAttachListener.target
│                          ~~~~~~
├─ androidx.appcompat.widget.AppCompatTextView instance
│    Leaking: YES (View.mContext references a destroyed activity)
│    mContext instance of co.anitrend.support.crunchyroll.ui.MainScreen with mDestroyed = true
│    View#mParent is set
│    View#mAttachInfo is null (view detached)
│    View.mID = R.id.newsPublishedOn
│    View.mWindowAttachCount = 17
│    ↓ AppCompatTextView.mContext
╰→ co.anitrend.support.crunchyroll.ui.MainScreen instance
​     Leaking: YES (ObjectWatcher was watching this because co.anitrend.component.MainScreen received Activity#onDestroy() callback and Activity#mDestroyed is true)
​     key = 331e1713-3a5a-4fdb-880e-4c188e9f4388
​     watchDurationMillis = 5455
​     retainedDurationMillis = 430

METADATA

Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: Xiaomi
LeakCanary version: 2.4
App process name: co.anitrend
Analysis duration: 14157 ms

To Reproduce
Steps to reproduce the behavior:

  1. Create a sample application and add leak canary
  2. Add blitz in a recycler - view holder implementation, make sure you add cancelTimeAgoUpdates() when the view holder is recycled
  3. Scroll up and down a couple of times, then exit the application or go to another activity besides the one containing the above recycler
  4. See error

Expected behavior
cancelTimeAgoUpdates() should take of any pending message queues for the view to avoid any potential leaks as, I have not taken a look at the codebase so I'm not yet sure about what could be done to mitigate this

Smartphone (please complete the following information):

  • Device: Xiaomi Poco F1
  • Android OS Version: 10
  • Blitz Library Version: 1.0.9

Additional context
Other devices affected:

  • Emulator(s): API 26 & 28
  • Blitz Library Version: 1.0.9

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions