-
Couldn't load subscription status.
- Fork 878
fix: Small Android memory safety improvements #1930
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
base: main
Are you sure you want to change the base?
fix: Small Android memory safety improvements #1930
Conversation
… player when it is no longer strongly reachable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the work done and making aware of these memory leaks.
Note that we also have the package audioplayers_android_exo which should also have the changes included. But we can do this after finishing the review for audioplayers_android, so no unnecessary duplicate work needs to be done.
...s/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt
Show resolved
Hide resolved
| mediaPlayer.setOnCompletionListener(null) | ||
| mediaPlayer.setOnSeekCompleteListener(null) | ||
| mediaPlayer.setOnErrorListener(null) | ||
| mediaPlayer.setOnBufferingUpdateListener(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I would prefer its own (interface) method dispose which is only called, when the player object is newly set or set to null. Otherwise it is hard to follow and this would implicate that the listeners are not used any more when released, which should not implicitly be the case.
...s/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt
Show resolved
Hide resolved
|
|
||
| fun dispose() { | ||
| if (isDisposed) return | ||
| isDisposed = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we somehow test this? What is the desired outcome? This should be aligned then on all platforms. I would expect it to throw, if a player is disposed twice, as this most likely is a mistake of the developer (?)
|
@Gustl22 I'm trying to implement what you suggested, but I have no idea what I'm doing in Java. 🤣 TBH, I just noticed a place where memory leaks might occur and used AI to help me write the Java code that could possibly help. If you feel like the memory leaks are valid concerns, please push this through the finish line, otherwise, you can close this PR and I won't be offended! Your call man, just trying to help. :) |
Description
I'm not well-versed in Java, but these changes might benefit the garbage collection and memory-safety of the plugin. I've double checked this functionality by running it in my game.
Checklist
fix:,feat:,refactor:,docs:,chore:,test:,ci:etc).///, where necessary.Breaking Change
Related Issues