How do you free ArrayMesh resource?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rain

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

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();

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

Ertain | 2019-11-21 01:29

Try storing them to an array and calling “free” function:

Object — Godot Engine (3.1) documentation in English

gmaps | 2019-11-21 08:28

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.

madgit | 2019-11-26 15:12

:bust_in_silhouette: Reply From: Chlipouni

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 …