I'm using LeakCanary but the heap analysis result doesn't provide enough information to detect any leak. It only mentions that the activity is leaking.
D/LeakCanary:
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
298153 bytes retained by leaking objects
Signature: a610bac3ef989ac5dc5a69244fc2882de5617
┬───
│ GC Root: System class
│
├─ android.provider.FontsContract class
│ Leaking: NO (MyApplication↓ is not leaking and a class is never leaking)
│ ↓ static FontsContract.sContext
├─ com.example.MyApplication instance
│ Leaking: NO (Application is a singleton)
│ mBoundService instance of com.example.services.SessionService
│ mBase instance of android.app.ContextImpl
│ ↓ Application.mLoadedApk
│ ~~~~~~~~~~
├─ android.app.LoadedApk instance
│ Leaking: UNKNOWN
│ Retaining 302.8 kB in 4641 objects
│ mApplication instance of com.example.MyApplication
│ ↓ LoadedApk.mReceivers
│ ~~~~~~~~~~
├─ android.util.ArrayMap instance
│ Leaking: UNKNOWN
│ Retaining 301.7 kB in 4615 objects
│ ↓ ArrayMap.mArray
│ ~~~~~~
├─ java.lang.Object[] array
│ Leaking: UNKNOWN
│ Retaining 301.7 kB in 4613 objects
│ ↓ Object[].[2]
│ ~~~
╰→ com.example.activities.SelectActivity instance
Leaking: YES (ObjectWatcher was watching this because com.example.activities.SelectActivity received
Activity#onDestroy() callback and Activity#mDestroyed is true)
Retaining 298.2 kB in 4579 objects
key = 68660c30-bc17-4a74-a5e2-c54f6d676c59
watchDurationMillis = 5185
retainedDurationMillis = 183
mApplication instance of com.example.MyApplication
mBase instance of androidx.appcompat.view.ContextThemeWrapper
====================================
0 LIBRARY LEAKS
All I know from this trace is SelectActivity is leaking. But I can't figure out why? The activity itself is 1000+ lines and I was hoping if there's any shortcut other than going though every line and checking for a possible leak candidate.
Does the activity register any broadcast receiver? The leaktrace shows LoadedApk.mReceivers which is an ArrayMap of receivers to receiver dispatcher and the activity is the receiver dispatcher.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With