Skip to content
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

Resource leak? #56

Closed
Eneum opened this issue Oct 30, 2018 · 2 comments
Closed

Resource leak? #56

Eneum opened this issue Oct 30, 2018 · 2 comments

Comments

@Eneum
Copy link

Eneum commented Oct 30, 2018

Using AudioCache player to repeatedly play a sound effect in a game-like app. on iOS, after a large number of plays, the sound disappears, and the whole app comes to a screeching halt, and then crashes. Looks like some sort of resource leak that gets accumulated over time.

@luanpotter
Copy link
Member

Hi, @Eneum

Each time the cache plays a new audio, if using the default configurations, it will create a new AudioPlayer and load the resource, but on RELEASE mode, meaning that as soon as it finishes playing, the player is released. That is, however, just on Android. On iOS, the release function does nothing, as I believed there was no need to release the media player for iOS. Maybe that's a problem with that?

To test this theory, you could set the fixedPlayer property on the audiocache and now every call to play will use the same player (you won't be able to play simultaneously, though).

The best way to handle this if you have possible overlapping sound is to use the AudioPool class provided by Flame. In fact, if you are building a game-like app, I'd suggest taking a look at Flame to help you out, it provides lots of goodies to help with games.

The AudioPool class can be found here; it creates a pool of pre-loaded audioplayers (you control min and max) to have one always ready for quick firing sounds but also don't overload the heap with tons of players.

The parameters are:

  • min : the minimal amount of players, upon creating it will leave this amount ready. if more than min happen to be created, they are kept (up to max)
  • max : the max to be kept, if more than max are created, they are released and discarded.
  • prefix : audiocache's prefix
  • repeating : probably false to you, but allows to play on repeat mode

Please let me know if this helps you out!

@erickzanardo
Copy link
Member

Closing this due inactivity, if you still have problems, feel free to open a new issue.

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

No branches or pull requests

2 participants