I managed to get pretty far with marching cubes infinite terrain generation, now threaded and working almost without any crashes. I'm stuck on one huge issue: As you keep exploring, memory fills up like crazy, to the point where you can easily pass 10 GB of RAM used by the process. This shouldn't be happening since the system removes chunks once they're past a certain distance, this can be confirmed by their visual disappearance until I get close to generate them once more. Why isn't all of the data being freed from memory then?
The removal of chunk nodes is done using queue_free() which is the advice I found everywhere, as a failsafe I even added a remove_child() after but the issue persists. The hierarchy of each chunk is a MeshInstance3D with a child of type StaticBody3D which itself has a child CollisionShape3D. This might be because I'm storing the mesh (ArrayMesh) and its collision (mesh.create_trimesh_shape()) in global dictionaries, but even if I use calls of the type meshes[pos].queue_free() the issue persists.
Looking at the monitors: No orphaned nodes at any point in time, 8 resources used at all times, the number of nodes goes up and down predictably as expected... only abnormality is the number of objects which only goes up and never comes down. Memory increase is consistent with those objects so that's surely where my issue lies.
