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)
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!
- mirkvid asked 8 years ago
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.
Please login first to submit.