After conducting a video call in our application, we observed memory leaks being logged. The leak seems to be related to TextureViewRenderer instances, which are holding references to a destroyed activity. This issue was detected using LeakCanary.
LeakCanary Log
`
1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
175409 bytes retained by leaking objects
Signature: da39a3ee5e6b4b0d3255bfef95601890afd80709
┬───
│ GC Root: Global variable in native code
│
├─ io.livekit.android.renderer.TextureViewRenderer instance
│ Leaking: YES (View.mContext references a destroyed activity)
│ Retaining 175.4 kB in 3367 objects
│ View not part of a window view hierarchy
│ View.mAttachInfo is null (view detached)
│ View.mWindowAttachCount = 1
│ mContext instance of [REDACTED].activities.CallActivity with mDestroyed = true
│ ↓ View.mContext
╰→ [REDACTED].activities.CallActivity instance
Leaking: YES (ObjectWatcher was watching this because [REDACTED].activities.CallActivity received
Activity#onDestroy() callback and Activity#mDestroyed is true)
Retaining 170.3 kB in 3321 objects
key = c5623187-0999-484e-bb56-5dc03dfebe9f
watchDurationMillis = 5285
retainedDurationMillis = 285
mApplication instance of [REDACTED].Application
mBase instance of android.app.ContextImpl`
Issue: Memory Leak in TextureViewRenderer
Description
After conducting a video call in our application, we observed memory leaks being logged. The leak seems to be related to
TextureViewRenderer
instances, which are holding references to a destroyed activity. This issue was detected using LeakCanary.LeakCanary Log
` 1 APPLICATION LEAKS
References underlined with "~~~" are likely causes. Learn more at https://squ.re/leaks.
175409 bytes retained by leaking objects Signature: da39a3ee5e6b4b0d3255bfef95601890afd80709 ┬─── │ GC Root: Global variable in native code │ ├─ io.livekit.android.renderer.TextureViewRenderer instance │ Leaking: YES (View.mContext references a destroyed activity) │ Retaining 175.4 kB in 3367 objects │ View not part of a window view hierarchy │ View.mAttachInfo is null (view detached) │ View.mWindowAttachCount = 1 │ mContext instance of [REDACTED].activities.CallActivity with mDestroyed = true │ ↓ View.mContext ╰→ [REDACTED].activities.CallActivity instance Leaking: YES (ObjectWatcher was watching this because [REDACTED].activities.CallActivity received Activity#onDestroy() callback and Activity#mDestroyed is true) Retaining 170.3 kB in 3321 objects key = c5623187-0999-484e-bb56-5dc03dfebe9f watchDurationMillis = 5285 retainedDurationMillis = 285 mApplication instance of [REDACTED].Application mBase instance of android.app.ContextImpl`