Deleting a Geometry efficiently

When I detach a geometry using detachFromParent() or detachChild() does that remove it from the scene efficiently? In other words, does it just detach it from its parent or does it also delete the related material, and deletes the actual geometry after detaching, and all appropriate Gc is done?

hte reason I am asking is that I’ve been stuck on a memory leak for weeks now and profiling is indicating that meshes might be the culprit and this only happens when I insert and remove geometries (LOTS of geoms)

detachFromParent and then setting it to null should do the trick, unless you’ve got a reference to it somewhere. If you are using physics, make sure to remove the physics controls as well

detachFromParent will not cause GC to run its own. Everyone’s games would slow to a crawl if that were the case. It does cause it to be available for GC (unless as wezrule says you are holding onto it somewhere else).

If Geometry is really causing your memory leaks then after removing them all when you take a heap snapshot in the profiler then you will still see thousands of them still active in memory. Then it’s just a matter of finding out where in your code is still holding a reference to them.

You could harderase it by using the BufferUtils.destroy method (eg get all geometrys in node, get all meshes and all buffers, then delete each buffer)

Of course if you use it somewhere else everything will explode.