Hi
Well, my latest game is really starting to come together. However, I've noticed something that I think is the cause of a memory leak.
ParentGame.SoundBank.PlayCue(
"spark_1");I've notice a positive allocation of memory whenever the "PlayCue" method on a SoundBank is called. This particular line of code is fired very regularly (its an electric arc sound) in my game.
I've been pretty religious about pre-allocating objects (and avoiding "new") in the game - To avoid unwanted garbage collection and break-up of game smoothness. Anyway. Memory allocation appears relatively stable until PlayCue is called.
Can anyone offer an advice - Is this a known issue Anyone got a way around this

Memory Leak Blues (PlayCue)
medel
Yes. The garbage collection is cutting off the sound. Back to PlayCue() it is then
What does audioEngine.Update() do
chrisb2
Using the PlayCue method is the recommended way to play sound effects. You should only create a cue object if you have a need to start, stop and/or pause a sound in your game (background music for example).
As far as the memory issues, are you calling audioEngine.Update() in your Update code That should help you with your leak.
foxster100
Nice idea. I tried it out. Unfortunately, once a Cue has been played, if you want to play the Cue again, it must be re-acquired (GetCue).
See ms-help://MS.VSExpressCC.v80/MS.VSIPCC.v80/MS.XNAFX.1033/XNA/Audio_HowTo_StopOrPauseASound.htm..
That said, using GetCue followed by an immediate Play() appears a lot less hungry on memory than PlayCue().
Unless anyone has any other observations, I would advise using the code...
Cue c = SoundBank.GetCue("foobar");
c.Play();
...And avoid SoundBank.PlayCue("foobar");
Its not perfect, but if you are firing a lot of sounds off, it certainly appears less leaky. Thanks for the suggestion Leaf
Santhosh Pallikara
Sveind
// call this once per cue
Cue spark = Soundbank.GetCue("spark_1");
// then each time you want to play the sound
spark.Play();
In other words, cache the cues that you are going to use.
Cheers,
Leaf.