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: A "stop" notification 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. Note: This behavior is new in Wwise v2009.3. Previously, a "stop" notification was posted to all playing sounds that were referenced by that bank.
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 playing, their sound structure remain in memory until they stop playing by themselves. Beware of looping sounds!
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.