+1 vote

From the Reference documentation:

References keep an internal reference counter so that they are automatically released when no longer in use, and only then. References therefore do not need to be freed manually with Object.free.

I tested creating 100000 ArrayMesh instances without doing anything with it or even creating references to it. I expected all the objects to be disposed of right away. When I looked in the Debugger Monitors tab, the objects were still there. when I looked at the memory used, it was still considerably higher than compared to running game without creating the 100000 instances. I thought maybe giving it time to get to dispose it would do the trick but that didn’t do anything even after at least 15 minutes.

How should I be disposing ArrayMesh instances to free resources?

Actual C# code used inside a _Ready() method:

for(int i = 0; i < 100000; i++)
    new ArrayMesh();
asked Nov 20, 2019 in Engine by rain (13 points)

I don't know much about ArrayMeshes. Maybe it has to go out of scope before the array is freed?

Try storing them to an array and calling "free" function:


Sounds like it might be related to this issue I raised a while ago. My suspicion (based on only little knowledge) is that it's something in the C#<->GDScript interface that's leaking. Trying to manually Free() things doesn't seem to help at all.

1 Answer

0 votes

In my project I use a lot of ArrayMesh.
As I associate them with a MeshInstance (myMeshInstance.mesh = myArrayMesh), when I use "call_deferred("free")" on the parent node, the ArrayMesh is freed to.
Hope that helps ...

answered Mar 21 by Chlipouni (54 points)
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.