0 votes

I'm trying to learn C# by using godot and i'm trying to write a 2D fov algorithm.

However i noticed that the static memory usage and amount of objects in memory skyrockets using the debugger monitor so i wrote a simple memory test to try to figure out how it works.

private void MemoryTest() { Polygon2D polygon = new Polygon2D(); }

Always results in a new Polygon2D object without getting rid of the reference to the old one so the amount of objects in memory constantly increase.

When using a native c# object such as a List the automatic garbage collection takes care of it and the memory usage remains the same.

I'm trying to get rid of the godot object from memory by using the method Dispose() but it doesn't work.

What am i missing?


asked Aug 9, 2018 in Engine by Svampen (64 points)

1 Answer

+2 votes
Best answer

Even if you use C#, you are still interfacing with Godot. Polygon2Dis a Node. Nodes are not reference counted in the engine, and their memory management model goes through parent-child ownership (parent deletes children when deleted).
So they need to be freed explicitely, using queue_free (if they are in the main tree) or free otherwise to make it take effect immediately.

answered Aug 9, 2018 by Zylann (15,242 points)
selected Aug 9, 2018 by Svampen
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.