Skip to content

Conversation

@gnarhard
Copy link
Contributor

@gnarhard gnarhard commented Jun 6, 2025

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

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, refactor:,
    docs:, chore:, test:, ci: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation and added dartdoc comments with ///, where necessary.
  • I have updated/added relevant examples in example.

Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Related Issues

@gnarhard gnarhard changed the title fix: Small Android performance improvements fix: Small Android memory safety improvements Jun 6, 2025
Copy link
Collaborator

@Gustl22 Gustl22 left a 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.

mediaPlayer.setOnCompletionListener(null)
mediaPlayer.setOnSeekCompleteListener(null)
mediaPlayer.setOnErrorListener(null)
mediaPlayer.setOnBufferingUpdateListener(null)
Copy link
Collaborator

@Gustl22 Gustl22 Jun 15, 2025

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.


fun dispose() {
if (isDisposed) return
isDisposed = true
Copy link
Collaborator

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 (?)

@gnarhard
Copy link
Contributor Author

@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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants