I have some problem freeing memory in threejs when i remove a mesh using scene.remove(mesh) the mesh is removed but seems that memory used from js is not released.
I'm using webglrenderer with buffergeometry for the mesh and windows.
I have some problem freeing memory in threejs when i remove a mesh using scene.remove(mesh) the mesh is removed but seems that memory used from js is not released.
I'm using webglrenderer with buffergeometry for the mesh and windows.
This can be dark side of the js memory usage.
First try to setup primitive value to your objects.
mesh.geometry.dispose();
mesh.geometry = null; // or undefined .
// `delete` also cool but not support for old browsers
// The delete keyword deletes both the value of the property
// and the property itself.
delete mesh.geometry
Another way (try some hack) :
mesh.geometry = VerySmallmesh.geometry //see for three.js how to do this if this is not correct mesh.geometry = null;
// try to override memory stack
You must be sure that this object is only instance of him self (how to say). Be sure you dont have a clone if you have than you will need to destroy him also.
Update : I want to say one more , use slice method for clearing arrays from object in forEach or for loop.
I have also faced the same issue while working with my project.I suspect that you are only removing the mesh from the scene, not from the memory.Try doing the below to free the memory.It's working for me.
if (mesh) {
scene.remove(mesh);
mesh.geometry.dispose();
mesh.material.dispose();
mesh = [];
}
Also, go through this StackOverflow discussion for further clarification. freeing memory in three.js