[Leak] Toast$TN leaking in Android 11
Author: KaustubhPatangeCreated Feb 21, 2021Updated Nov 10, 2022
The leak is captured from LeakCanary.
┬───
│ GC Root: Global variable in native code
│
├─ android.widget.Toast$TN instance
│ Leaking: UNKNOWN
│ ↓ Toast$TN.mPresenter
│ ~~~~
├─ android.widget.ToastPresenter instance
│ Leaking: UNKNOWN
│ ↓ ToastPresenter.mContext
│ ~~~~
╰→ com.kpstv.yts.ui.activities.FinalActivity instance
Leaking: YES (ObjectWatcher was watching this because com.kpstv.yts.ui.activities.FinalActivity received Activity#onDestroy() callback and Activity#mDestroyed is true)
key = c2fb5f4f-112b-4489-a84e-8b37699b32c1
watchDurationMillis = 6111
retainedDurationMillis = 1110
METADATA
Build.VERSION.SDK_INT: 30
Build.MANUFACTURER: samsung
LeakCanary version: 2.4
App process name: com.kpstv.yts
Analysis duration: 33287 msThis happens when the toast is in the queue (referenced) but the activity or containing fragment (in which it's about to show) goes out of existence. I've tested in on some devices & found out that Samsung devices are hotspots for this leak.
The fix, for now, is to set allowQueue to false from Toasty.Config.
Source: GrenderG/Toasty