0
0

Hi Guys, Looks like i’m getting a memory leak for every sound that gets played. I’ve created a wrapper class to handle sound for a project i’m working on. I’ve followed the examples in the API doc very closely…

here is where I think the problem might be:

FMOD_RESULT FMODMNGR::AddSound(char* path, float vol)//System* system)
{
FMOD_RESULT result;
result = FMOD_OK;

//sound and channel are static members of my FMOD class

result = system->createStream(path, FMOD_DEFAULT, 0, &sound);        
result = system->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
channel->setPan(0.0f);
channel->setVolume(vol); 

return result;

}

now each time I play a sound the amount of memory the program uses increases. If I set a memory limit by calling FMOD::Memory_Initialize(…) then the sound will stop playing when my memory limit is reached.

You guys have a great forum here, any help would be much appreciated!

Jason

  • You must to post comments
0
0

Hi Jason, welcome to the forums!

in FMOD the ‘create*’ functions allocate memory, they all have a matching ‘release’ function.

Use Sound::release to free the memory this object is using.

-Pete

  • You must to post comments
0
0

Thanks for the quick reply Peter! Should I release the sound right after the system->playsound() call, or do I need to check its status to see if it is being used?

again, thanks!

  • You must to post comments
0
0

You should only release the sound when you have finished playing it. The idea is the FMOD::Sound object controls your memory usage and the FMOD::Channel controls playback.

For most short sounds that you would play multiple instances of you would use SAMPLE or COMPRESSEDSAMPLE, with these modes you only need to create the sound once and you can play that sound multiple times. When you’ve finished using that sound you can then release it. The Sound and Channel objects are very different to each other in purpose and lifetime.

Note: streams are an exception because you must createSound for each playSound when using streams. I noticed you’re using createStream, streams are great for music and dialog but generally samples are better for everything else.

As a side note:
If you were looking for a way to just have a ‘playSound’ interface that will hadle all the loading/unloading, then you could store all the Sound objects in a shared location so it can look-up and load it if it isn’t there. Then you could use a ref count to release it at the right time.

  • You must to post comments
0
0

Thanks Peter, I’ll give it a shot tonight!

  • You must to post comments
0
0

OK got it working easily enough. Thanks again for all your help, this wasn’t clear in the API docs!

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.