Here are some findings where memory is lost in the new Crystal Space sound system.
1. CS/plugins/sndsys/element/ogg/oggdata2.cppThe function
SndSysOggSoundData::IsOgg() allocates memory for OggStreamData, but never releases it.
This is no big deal because sound files are loaded only once and it is a wasted memory, but nothing that would take the client down.
2. CS/plugins/sndsys/renderer/software/renderer.cppThe sound engine is supposed to remove sounds and release memory automatically if said so with the
iSndSysStream::SetAutoUnregister() function. Planeshift uses that method in several places like for the background music and for interface sounds (the \"click\" sound when a button is clicked with the mouse). Unfortunately the sound engine only removes these sounds from the list, but forgets to decrement the reference counter, so these sound streams and sources will be never released.
It is a small but steady memory leak depending how often one clicks on different buttons and crosses sectors to change the background music.
3. CS/plugins/sndsys/renderer/software/source.cppThis is the big one. Effects like spells, combat sounds etc. use the
SndSysSourceSoftware3D sound source object. SndSysSourceSoftware creates 6 sound filters for 18 sound channels in the
SndSysSourceSoftware3D::SetupFilters() function, which are never deleted. In addition, some of these filters allocate memory for processing sound samples which is also never released. Memory allocated and never released for one single sound effect in one of the tests I did was 724 KB.
4. src/common/effects/pseffectobjsound.cppThe only sound related memory leak in Planesift code that I found
If sound is enabled in the PS setup, but muted in options (or muted because the game window lost focus), the game still creates
psEffectObjSound objects, but never deletes them. These objects are deleted when the sound effect stops playing, but since sound effects are muted, they are never started.
After fixing the memory leak no. 3 the client was still leaking memory, but now we are talking about 60 MB in 30 minutes when standing at the Arena and not 500 MB in 8 minutes like it was before (Arena is usually filled with spells, combat sounds etc).