How do you debug memory leaks?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Atlinx

When I run my game there are certain scenarios where its memory usage can increase indefinitely. I’ve noticed this after opening the debugger and seeing the total static memory usage rise.

I’ve tried running my game with the verbose flag but the console does not inform me of any memory leaks. Additionally, within the debugger, the total object count remains the same.

Is there a way to get more information about the memory usage of my game other than seeing the total static memory usage?

:bust_in_silhouette: Reply From: sash-rc

I suggest you’re using GDScript.

Try Objects - Orphan nodes (nodes, that were created, but haven’t been added to a tree, or removed but not freed).

Also, check accuracy of your allocations for Arrays, PoolArrays and Dictionaries.

:bust_in_silhouette: Reply From: Atlinx

Turns out the memory leak was caused by the built-in RegEx class. Everytime you call search() on a RegEx object it leaks memory. I’ve submitted an issue on the github here.