Investigating possible memory leak


We’ve been struggling with an apparent memory leak for a while now and as much as I investigate I just can’t find where it is, all instances eventually get correctly removed. This ‘leak’ becomes specially apparent when using our internal automatic testing system that plays the game at a high speed, so lots of sounds can sometimes pile up (but not to infinity, I monitored the number of events and it never kept on going up).

We use FMOD 2.01.05 on a custom engine PC and PS4 game. FMOD Studio is also used. Our initialization looks like this:

FMOD::Studio::System *m_soundSystem;

FMOD::System *lowLevelSoundSystem;

lowLevelSoundSystem->setSoftwareFormat(48000, FMOD_SPEAKERMODE_STEREO, 2);


settings.cbSize = sizeof(FMOD_ADVANCEDSETTINGS);
settings.vol0virtualvol = .001f;

FMOD::Studio::Bank *m_bank;
m_soundSystem->loadBankMemory((const char*)MicroROM::dget(""), MicroROM::sget(""), FMOD_STUDIO_LOAD_MEMORY_POINT, FMOD_STUDIO_LOAD_BANK_NORMAL, &m_bank);

Other than investigating and making sure (to the best of my knowledge) that FMOD is being used correctly, I tried doing a couple things to try to get more information:

  1. On one hand I ran the test using the FMOD debug libraries and it seems the AsyncCommandBuffer keeps on having to increase in size for some reason and eventually fails. For some reason this always happens around the 350MB mark even if my system has a lot of spare memory. I pasted the whole debug ouput to this hackmd link in case there’s some important piece of information in there:

  2. On another hand I made sure there were no obvious leaks by attaching a session of FMOD Live and checked that instances weren’t growing up against my will. I can confirm that after several hours the memory usage has increased and yet the values on “Voices (Self)”, “Lifespans” and “Instances (Self)” have been kept more or less constant (some are even lower at the time of checking, but that’s probably just due to there being less sounds playing at this moment). I’m assuming that if I was incorrectly leaking instances or any stuff FMOD-related this is were it would show (please correct me if I’m wrong).

I’m assuming my usage of FMOD is what’s causing these issues, but is there any document or any hint that someone can give me to see if I spot what the culprit is?

Thanks in advance. Please, let me know if there’s any other piece of information that would be helpful.

If the command queue keeps growing it means perhaps Studio::System::update is not being called regularly.
Also, the job list expanding means a bunch of objects are being created but not necessarily being cleaned up, also possibly related to update not being called.

If you record a profiler capture, then switch to the command view you can see all the Studio API calls your game is making for each update. Is the command list quite long at any points?

Hi, Mathew,

Apologies for the delay, I’ve been away for several weeks.

I just profiled and I do notice that certain frames are filled to the top with calls to EventInstance::setParameterByID. I had added a ‘dirty’ system to our game so that only the parameters that actually change call that function so they should be the bare minimum and I just made sure that Studio::System::update gets called once all setParameter calls have been made.

Have you tried enabling memory logging with FMOD_STUDIO_INIT_MEMORY_TRACKING. That should give you per-event info about where the memory is going.

Hey Mathew,

I’m going to close this issue because a restructure that we made seems to have fixed the problem so there must have been some sort of memory leak after all that was, for some reason, making FMOD fail every time.

Apologies and thanks for the support, much appreciated!