Manually drawing font causes object count to increase and never decrease
Godot version is 4.7 stable mono (though writing in GDscript)
I'm creating a nonogram game and I'm drawing everything manually through code. Up til now, I didn't realize I had an unchecked memory leak caused by using Font.draw_string() function. I'm currently using the RenderingServer to draw my game because it's much more flexible than other methods.
I'm drawing strings in process whenever my camera moves around the screen. Only draw_string/draw_string_outline are causing issues with the object count. I'm not sure what to do to fix this.
In the above code, I use get_theme_default_font(), I'm sure that that is not an issue. I've tracked it's reference count and it remains stable at a count of "2" for the entirety of runtime.
Using the ObjectDBProfiler I've whittled down the memory leak to an unchecked ImageTexture and Image count somehow related to using draw_string()
Snapshot during runtime before
Snapshot during runtime after some movement
Checking one of the RefCounted objects in the profiler shows no useful information.
In addition to the above code, I did originally have all this in _draw() but discovered the exact same occurrence of the memory leak when going back to those methods.
I'm sure this is the cause of the memory leak because removing the code completely gets rid of these issues.
What's going on here and how do I clear references caused by drawing fonts with code?
Posted Aug 29, 2026, 1:24 PM UTC