Currently there is no built-in method to release all active EventInstance globally.
At this time, the most suitable approach would be to implement a centralized manager that keeps track of all created EventInstance.
Generally, we recommend releasing EventInstance immediately after starting them, so that they are automatically cleaned up when playback ends, minimizing the need for manual management.
However, if that structure doesn’t suit your project, a possible alternative would be to:
Thank you for the suggestion. I believe your approach is likely superior to what I had in mind.
Since resetting the game won’t be a very frequent operation,
Whereas with my initial idea: using an array to track all Events created via CreateInstance, and updating that array whenever these EventInstances are Released – would clearly add significant performance overhead.
I have another question I’d like to consult you about.
Suppose an EventInstance is currently playing, but the Bank it belongs to gets Unloaded.
At this point, a warning appears:
[FMOD] PlaybackSystem::onDestroyEvent : Destroying event instance ‘2005a0’ due to event description {6f0e2732-db89-4496-a8d9-4c019913d480} unload
In this scenario, is the state of this EventInstance the same as if I had called stop() and then release() on a regular EventInstance?
Additionally, we are evaluating the long-term stability of our project.
While it seems to me that an EventInstance is just a wrapper, and the handle it holds is merely an IntPtr,
I want to confirm: do EventInstances that have been release()d still occupy some system resources?
Or does FMOD perform garbage collection (GC) on them at specific times?
(Assuming the number of released EventInstances exceeds ten thousand.)
Based on my observations of the Instances item in the Profiler, it appears consistent with my speculation.
After release(), the Instances count rapidly drops to 0/0.
Similarly, after Unloading a Bank, the Instances count also rapidly drops to 0/0.
This leaves me with only one point of confusion: are the two approaches equivalent?
Can I achieve similar results as release()ing all EventInstances by leveraging the method of Unloading all Banks?
Unloading a bank is not equivalent to manually calling stop() followed by release() on an EventInstance.
If a bank is unloaded while one of its event instances is still active, FMOD destroys the instance immediately, bypassing the normal stopping and releasing process. This abrupt termination can lead to incomplete cleanup and potential resource leaks.
Calling Studio::EventInstance::release marks the event instance for destruction, which occurs asynchronously once the instance reaches the STOPPED state. This is the recommended method for managing event lifecycles.
FMOD does not perform a garbage collection on EventInstance objects. It relies on explicit release() calls to free resources. Without releasing instances properly, even if playback has stopped, they can accumulate and consume memory over time.