[C# Godot 3.5.1] Memory leak issue

Godot Version

Godot 3.5.1, Mono

Question

So I made a game that has some king of auto mode, that create an UI, do something, and closes the UI.
This is working great, but I suspect this process still eats memory even if I take correctly care of Orphan node and if I queue_free any nodes of my UI.
Here is a Memory graph showing what happens after openning/closing this UI multiple times (each spike is one iteration).

We can see that there is no Orphan nodes, and the nodes are taken care correctly. But, the objects aren’t.
And i honestly don’t know what I do wrong. I’m coding on C# so the garbage collector should free everything I suppose. Just in case, I put all my scripts variables to null at the _ExitTree() call.

I’m using mutltiple AudioStreamPlayer, Particles2D, AnimationPlayer, Sprites with custom materials and UI nodes during the process. Is there something I must free in a specific way ?

Thanks,

Clement.

Any object that does not inherit Reference must be freed manually. Though I’m not sure how you would easily find those.

C# Garbage collection should kick in if ‘stuff’ is no longer referenced, and isnt Godot specific. Anything that uses ‘Node’ should be freed by Godot, so it seems there is still a reference somewhere to those objects.

Unless you have UI attached to some sort of character in your game, then you should set your game up to just have one set of UI objects and disable / enable as required.

Also you might want to consider moving to 4.0 C# is a lot better in 4.

I was on 3.5.1 because my game is for android/iOS. and Godot 4.0 didn’t have support for mono on those platforms at first. No idea if this is better now.

1 Like

Godot 4.2 .Net don’t support only WebGL and Android/iOS is still in experimental phase.
For android you needed .NET 8.0

I’ll wait a little more then.