-
Notifications
You must be signed in to change notification settings - Fork 406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MediaSessionService leak #346
Comments
To be clear: I use a pure MediaSessionService approach, my Manifest does not declare MediaBrowserService, so I'd think that media3 should be expected to handle this cleanly, without baggage from legacy code & requirements. I have some bound services of my own in the same process as MediaSessionService. Those are garbage collected cleanly. I have verified these behaviors on APIs 33 & 32. UpsideDownCake 34 Beta1 appears to leak all services whatsoever. |
Also, I see that the leaking behavior is more significant if there is no significant interaction between MediaController & MediaSession. In this case the MediaSession is torn down when the MediaController calls release(), the MediaSessionService is destroyed and leaks. In the case where there is more interaction, the MediaSession does not seem to be released upon MediaController.release(), and is reused when a MediaController connects again. May be another bug, or I'm doing something wrong. I thought it would release right away in the case of a pure MediaSessionService, as opposed to when it also supports MediaBrowserService compatibility. |
I can reproduce a similar leak that looks slightly different, which I assume is due to differences in the type of controller and/or the interactions caused with it. In any case, fixing the leak I can reproduce affects the same code location your leak above is complaining about, so I'd assume it fixes this as well. |
I found a bug in AndroidX code that caused the leak in the "little interaction" case. However, now there is still a somewhat lengthy delay of about 10 seconds from onDestroy() to being finalizable on my MediaSessionService. If I trigger a GC at 11 seconds, it will be finalized, with 10 seconds it won't. Can this be reduced? It tends to trigger spurious leak reports. I also still don't understand the second case: Why will the MediaSessionService not be destroyed if is there is meaningful interaction prior to releasing the MediaSession? |
Thanks for detailed investigations - feels like you found a few interesting edge case bugs in our libraries! I'd suggest you retry your tests once the Media3 fix is uploaded to GitHub. If there is another (different) leak you can reproduce in Media3 code after including the fix, then please open a new issue. If you see any leaks reported in other libraries (Android system code or |
References to the service are kept from MediaSessionStub and from a long-delayed Handler messages in ConnectionTimeoutHandler. Remove strong references from these places by making the timeout handler static and ensuring ConnectedControllersManager only keeps a weak reference to the service (as it's part of MediaSessionStub). Issue: #346 PiperOrigin-RevId: 527543396
Thanks for the fix! I'm not sure how to publish the project artifacts, in particular Edit: just saw the brand new commits on main suggesting an imminent alpha release, so will wait for that to drop. Still would be nice to know how to get this going myself without manually copying artifacts around. Or is there a repo for nightlies? Also tried using via project(...) dependency from README, but this project looks incompatible with AGP 8.0+. What a waste of time. |
To depend on the latest dev branch, you'd need to checkout the sources and depend on them locally. See https://github.com/androidx/media#locally for details. We are also planning to publish a |
I'll close this issue under the assumption that it is fixed. If you still see something similar (in media3 code), please reopen or file a new issue. |
Thanks. Like I mentioned earlier, depending on media3 project locally fails due to my project's build setup being incompatible with media3. In particular, I use the current AGP 8.0+, and media3 does not. I'd expect this recommendation to not work smoothly in general. This being a public Github project, it would be desirable to have a way to test out artifacts that's less dependent on requiring me to have a build setup that's compatible with whatever you guys have. |
I've validated that the 10 second finalization delay leak is fixed in 1.1.0-alpha01. Yay and thanks! The problem with the MediaSessionService not reaching onDestroy() after some amount of player interaction is still present. I will create a new issue. |
References to the service are kept from MediaSessionStub and from a long-delayed Handler messages in ConnectionTimeoutHandler. Remove strong references from these places by making the timeout handler static and ensuring ConnectedControllersManager only keeps a weak reference to the service (as it's part of MediaSessionStub). Issue: #346 PiperOrigin-RevId: 527543396 (cherry picked from commit 8c262d6)
Media3 Version
Media3 1.0.1
Devices that reproduce the issue
Android emulator API 33
Devices that do not reproduce the issue
No response
Reproducible in the demo app?
Not tested
Reproduction steps
Expected result
MediaSessionService garbage collected
Actual result
MediaSessionService leaks. Is this a known leak or expected? If so, is there a workaround? If it's not clear what's going on here I can work on a repro.
It looks like something (Binder-related I assume) is keeping a reference to MediaSessionStub.
Media
N/A
Bug Report
adb bugreport
to dev.exoplayer@gmail.com after filing this issue.The text was updated successfully, but these errors were encountered: