Memory Leak error MediaBrowserService.ServiceBinder.mBase
Example: https://github.com/Kolyall/MediaBrowserServiceLeak Error:
┬───
│ GC Root: Global variable in native code
│
├─ android.service.media.MediaBrowserService$ServiceBinder instance
│ Leaking: UNKNOWN
│ Retaining 10,1 kB in 96 objects
│ this$0 instance of androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi26$MediaBrowserServiceApi26
│ ↓ MediaBrowserService$ServiceBinder.this$0
│ ~~~~~~
├─ androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi26$MediaBrowserServiceApi26 instance
│ Leaking: YES (Service not held by ActivityThread)
│ Retaining 9,6 kB in 95 objects
│ mBase instance of com.github.kolya.myapplication.service.MusicService
│ ↓ ContextWrapper.mBase
╰→ com.github.kolya.myapplication.service.MusicService instance
Leaking: YES (ObjectWatcher was watching this because com.github.kolya.myapplication.service.MusicService
received Service#onDestroy() callback and Service not held by ActivityThread)
Retaining 7,7 kB in 81 objects
key = 64f61139-e21a-47d3-8759-b1c9c5be6d83
watchDurationMillis = 5199
retainedDurationMillis = 178
mApplication instance of android.app.Application
mBase instance of android.app.ContextImpl
METADATA
Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: Google
LeakCanary version: 2.8.1
App process name: com.github.kolya.myapplication
Stats: LruCache[maxSize=3000,hits=34152,misses=85683,hitRate=28%]
RandomAccess[bytes=3961419,reads=85683,travel=23994363586,range=16504510,size=21876036]
Analysis duration: 3061 ms
Any update on this?
We (Audiomack) are also experiencing the same problem. Could someone please have a look.
34134 bytes retained by leaking objects
Signature: 0f0ab14a66b16eeae7988b3415bfdc35ce9d42
┬───
│ GC Root: Global variable in native code
│
├─ android.service.media.MediaBrowserService$ServiceBinder instance
│ Leaking: UNKNOWN
│ Retaining 34.7 kB in 607 objects
│ this$0 instance of androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi26$MediaBrowserServiceApi26
│ ↓ MediaBrowserService$ServiceBinder.this$0
│ ~~~~~~
├─ androidx.media.MediaBrowserServiceCompat$MediaBrowserServiceImplApi26$MediaBrowserServiceApi26 instance
│ Leaking: YES (Service not held by ActivityThread)
│ Retaining 34.1 kB in 606 objects
│ mBase instance of com.audiomack.playback.MusicService
│ ↓ ContextWrapper.mBase
╰→ com.audiomack.playback.MusicService instance
Leaking: YES (ObjectWatcher was watching this because com.audiomack.playback.MusicService received
Service#onDestroy() callback and Service not held by ActivityThread)
Retaining 32.8 kB in 594 objects
key = 01674233-fcdd-4b67-9f0c-3e71a87465eb
watchDurationMillis = 5046
retainedDurationMillis = 33
mApplication instance of com.audiomack.MainApplication
mBase instance of android.app.ContextImpl
METADATA
Build.VERSION.SDK_INT: 29
Build.MANUFACTURER: Google
LeakCanary version: 2.7
App process name: com.audiomack
Stats: LruCache[maxSize=3000,hits=9611,misses=134435,hitRate=6%]
RandomAccess[bytes=7038717,reads=134435,travel=77402448250,range=32208329,size=38741613]
Heap dump reason: 9 retained objects, app is visible
Analysis duration: 36965 ms
Heap dump duration: 4190 ms
It's this: https://issuetracker.google.com/issues/220795151
Supposedly "fixed" years ago, but no.
I first reported this issue 6 years ago, and Google did not even look at it: https://issuetracker.google.com/issues/37137738
Was hoping the implied "fix" meant switching to Media3 and MediaSessionService/MediaLibraryService, but after a huge refactoring effort I see a comparable leak there now: #346
As noted above, this is essentially a duplicate of the issue tracked at https://issuetracker.google.com/issues/220795151
The underlying issue is an Android platform bug that got fixed in Android 13 (API 33) with no good way to backport/workaround the problem on earlier platform versions. So the leak detections above can't be solved as they are both on API 29.
@bubenheimer : You stated on the linked platform bug that this is still present in Android 14 DP2. Are you certain is the exact same leak mentioned here and in the bug, or are you referring to https://github.com/androidx/media/issues/346 (which is different and can be fixed in Media3)?
I've just repro'ed my own issue again (https://issuetracker.google.com/issues/37137738) on my production app (based on MediaBrowserServiceCompat), on API 33. This is distinct from #346. Maybe it's not the same as https://issuetracker.google.com/issues/220795151 (which does not have a repro, but looks the same as this reproable Github issue), the leak trace looks different. They all seem to make MediaBrowserServiceCompat leak without recourse.
Let's continue tracking the platform andandroidx.media related issues on the linked bugs where they belong and close this one. #346 can be addressed separately.