Prevent memory leak with layout test and counting malloc/free
It would be great if we could make sure that the loading and unloading of scores doesn't leak. (In MuseScore 2, we know it's not the case...)
We could add a test, on linux as follow.
- Create a global variable memory_usage
- Use malloc hooks https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html to increment and decrement the memory_usage on malloc and free
- Set the memory_usage to 0 and load a score
- Delete the score and check memory_usage. It should be 0 or we have a new leak.
It wouldn't really help to find the leak but at least it would avoid regression.
Any developer on Linux wants to try this?
Comments
Do we really use malloc() and free() rather than new and delete?
I did a quick search and found malloc only in fonttools (1), freetype (5), poppler (12) and portmidi (1)