Memory leak with programmer instrument

Hi

I’m working on a commentary system so I configured a programmer instrumment and works fine, but I realized that when I see the Fmod studio debug window, the current memory increase and the max memory is not being cleaned. I was trying to unload sample data from my bank when the script is destroyed and putting the release() function exactly next on the start(), but I realized that the event state is always Stopping and never reach Stopped state. I was trying to forced the event state to be stopped with stop() with immadeate parameter and then running the release function but nothing seems to work. The event has delay and reverb effects setted in Fmod studio.

Thanks

Hi,

What version of the FMOD integration are you using?

Would it be possible to get a code snippet of how you are triggering and stopping the event and a screenshot of the event in FMOD Studio?

Using 2.02.18 I was not able to reproduce the issue

I’m using version 2.02.12 of Fmod Studio. Basically I’m creating an instance and releasing the event as in the example for programmer instrumment, the thing is that the programmer instrumment has been used into a coroutine to matcha audios to complete a sentence. I was checking that the stopped state was reached by the event, so I forced it to stop (with Immediate option) and to release after create any instance of the event and that allows the event to reaching now the Stopped State, but the cur memory in Fmod Studio Debugger is not been cleaned. I try unloading the bank and the sample data once the script has been destroyed, but memory is still stacking.

There is the code for function that play sounds

    {
        m_event = FMODUnity.RuntimeManager.CreateInstance(EventName);

        if (needsLengthReturn){
            m_needsLengthReturn = true;
        }

        // Pin the key string in memory and pass a pointer through the user data
        GCHandle stringHandle = GCHandle.Alloc(key);
        m_event.setUserData(GCHandle.ToIntPtr(stringHandle));
        m_event.setCallback(dialogueCallback);
        m_event.start();
        m_event.release();
    }

And the screenshot of my event:

Hi,

Thank you for sharing the code.

I would suggest not calling release() straight after start() if you are going to interact with the m_event reference as it may be in an invalid state and not stopping the correct reference.

Which value are you checking against when you are seeing the increasing memory usage?
image
cur or max?

Most FMOD functions return FMOD_RESULT (FMOD Engine | Core API Reference - FMOD_RESULT), I would suggest adding some error checking to make sure that your stop() and release() functions are running successfully.

Thank you for the image, would it be possible to see the effects on the event:

Hi Connor, thanks for reply and I will answer in parts to have more clarity:

1. I paid attention to your recommendation to avoid releasing the event once I started, but it doesn’t work because as I mentioned elsewhere in the thread, I was creating an event and trying to release it immediately, every time the code played a sound (exactly as is in the example script), which in this case is not recommended, so I created a single event that is only released once the script is destroyed.

2. Instead of working around trying to release the event, I released the sound (type FMOD.Sound) which is in the programmer instrument callback and was created by getting the audio from the audio table on each sound I needed to play. This release is executed before a sound is played.

3. Before implementing this fix, every time I played a match in the game I would get a current memory performance that was not cleared and the maximum memory would increase by 4 or 5 MB. The current memory is now being cleaned and the increase in the maximum memory is not more than 1mb, but still the latter is not cleaned once I pause the game and start a new one from unity.

4. Event effects was not a problem and was not affecting the releasing.

Hope this works for someone else.

Hi,

Just to confirm, were you able to solve the issue?

If so, thank you for sharing the solution!

Yes, it works.

1 Like