Add/Remove scene object geometry memory leak related

I have seem to be able to create the memory leak bug I talked about before.

It seems that adding and removing Meshes in THREE.js from a scene, creates a memory leak in VRAM.
This seem to be related to geometry, as the following sample is not using texture and if you change the divisions of the sphere, the memory leak speed change.

I see no usage of dispose() methods in your code. Please read this guide for more information:

1 Like

I have updated the sample to include dispose of the geometry, and the memory leak disappeared.
However, I still see issues of memory leak in my app. I will try to update the sample here to reflect that.
The issue is basically related when I use THREE.Geometry for the geometry instead of SphereBufferGeometry

Notice it’s never recommended to massively spawn objects of any kind in realtime, you should use global objects or pooling, the GC at some point might not keep up anymore and the page will crash, generally you will experience a bad performance from major GC hickups.

With pooling you can archive the same as with creating objects, but without the performance degeneration or cluttering memory.

1 Like

Even with pooling I have the same issue.
I am trying to make an example, but I get script error when I set the geo1 as the geometry instead of the sphere geometry.

Ok, this sample has memoery leak in VRAM.
It’s not a fast memory leak, but if you wait enough you will see it’s slowly taking more and more VRAM.

I’ve answered you here:

1 Like