I recently encountered a memory leak. I checked it and found it in the fmod module.
If it weren't for all other components to customize the memory allocation function, I wouldn't doubt it.
Use fmod: EventSystem: getmemoryinfo () to output the memory information. It crashes, MB ~ 200 MB
I used xact before, and fmod thought it was similar, so I didn't care much about it.
I read the document in detail and found that there are three points:
- Fmod: memory_initialize
- You can replace the fmod memory distributor with your own memory to conveniently measure the internal usage of each module.
- This function must be linked to the fmodex Lib, which is not applicable only to the Lib of the fmod event.
- This step is optional, but our memory analysis tool is better at analyzing the memory module allocation, so we have customized it.
- Fmod: Event
- The playing sound will allocate some memory. If you do not recycle it, fmod will not be released unless you unload the entire project (. FEV ).
- Generally, level-based Games use the management of switching projects, which is not very suitable for mmog. Therefore, you still need to regularly use fmod: eventgroup: freeeventdata () for memory reclaim.
- The original code is really messy, so I can't stand to rewrite it. Change it to recycle it based on reference count and playback status.
- Soundbank
- This is similar to xact. Generally, sound effects are directly loaded into memory (memory), and background music is streamed (Stream)
- In order to save disk and memory usage, encoding and compression are generally performed. I am used to using ADPCM for sound effects, MP3/xwma for music, and CPU decoding (which can be directly supported by hardware) can be ignored.
- Fmod has an additional loading method: "decompress into memory ". decompress the compressed audio data to the memory for playback. you need to know that the extracted background music has dozens of MB...
- Check that our soundbank was set to "decompress into memory", and the audio project was created by a program, so it would be better for the production staff to fill in the data -_-!
- I made an agreement with the sound engineer: The sound effect uses "load into memory" + "ADPCM", and the music uses "stream from disk" + "MP3"
After the above changes, the memory occupied by fmod in normal games is usually about 3 MB, and the peak of fierce combat traffic will not exceed 10 MB. In a short time, it will be recycled back.