Freeing memory with threejs

强颜欢笑 提交于 2019-12-23 03:25:48

问题


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.


回答1:


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 .
//also cool
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.




回答2:


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



来源:https://stackoverflow.com/questions/39904976/freeing-memory-with-threejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!