Objects in the Wwise sound engine are ref-counted:
- Soundbanks hold a reference to all their events, sound structures and media.
- Playing sounds hold a reference to their sound structure, and to their in-bank media if applicable: in-memory sounds and streaming sounds using prefetched data ("zero-latency streaming") have in-bank media, while pure streaming sounds and source plugins don't.
The soundbank unloading process does not wait for sounds to stop playing; it simply releases all references held by the soundbank being unloaded and returns.
Here's what happens in details when you unload a bank.
- Events: All events are released. If they are not referenced by another bank, they are therefore unloaded.
- Sound structures: All sound structures are released. Thus, if they are not referenced by another bank, and if they are not playing, they are unloaded.
- Media: All media data is released. Thus, if they are not referenced by another bank, and if they are not playing, they are unloaded.
- Playing sounds: An internal "stop" action is posted to all playing sounds which reference media that was stored in that bank. When these sounds stop, they release their reference to both their sound and media, which are then unloaded.
In summary, in-memory sounds and streaming sounds with prefetched data are stopped when you unload their bank, and are then destroyed. On the other hand, pure streaming sounds and source plugins are not stopped. Thus, if they continue to play, their sound structure remain in memory until they stop playing by themselves. Beware of looping sounds! Likewise, high-level playing instances, like interactive music, are not stopped. You may stop hearing interactive music, because all the audio clips have been unloaded, but the logical instance is still playing. The "Number of active events" in the Performance Monitor of the Wwise tool may help you detect such "ghost instances".
The reason why sounds are not stopped explicitly when unloading a bank is to let you duplicate media and sound structures in different banks, and swap them on the fly without stopping the sound. For example, you may design your bank structure so that your interactive music tree is split up into several banks: load the new subtree, change the state to perform a music transition, and then unload the old subtree.
If you want to stop sounds when you unload a bank, you need to use one of the services exposed to you by Wwise before unloading it: create and call appropriate stop events, use AK::SoundEngine::ExecuteActionOnEvent(), or AK::SoundEngine::StopAll().
Note that when a sound (structure) remains in-memory because a playing instance of that sound still holds a reference to it, only that sound and all its ascendants structures (containers, actor-mixers and so on) remain in-memory. Their siblings are unloaded if they are not themselves held by a playing instance.