How can I remove meshes from three.js scene completely without causing memory leaks. I could find that loading the same models again and again causes the browser to crash, so it seems like the memory is not being deallocated.
Use the dispose
method on the geometry and material. Also, ensure that nothing is holding references to these objects, as that will prevent garbage collection.
var myMesh = new THREE.Mesh(geo, mat);
scene.add(myMesh);
//...
scene.remove(myMesh);
myMesh.geometry.dispose();
myMesh.material.dispose();
myMesh = undefined;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With