r/godot•
Live-Common1015

Manually drawing font causes object count to increase and never decrease

help me

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.

Object count going up over time. The little lip at the beginning is the Object count at the start of playing before I move the camera, after moving it exponential increases as my draw functions are called over and over. The interesting this is that it plateau's after a while even though I haven't stopped moving the camera around the screen, meaning that even though draw_string() is occurring constantly there is a reference count somewhere that stops increasing for some reason.

Code for drawing the string. The calculations aren't an issue. Only, font_choice.draw_string() causes the count to go up. I commented out the draw_string_outline code to test if that specifically was causing issues. it wasn't.

How I call the above function. left_measurement_RIDs are the individual placements of numbers indicating the cell count going up/down/left/right on a nonogram grid (it can help with oriented yourself when playing zoomed in). I don't believe there's anything really unique going on here since I'm clearing the RID before drawing. I have a dictionary of the RID's because it gives me a lot of control over manually moving measurements around the grid. Because I'm iterating through large grids, I am able to see such large jumps in the Object count

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

49
Loading comments…