用threejs释放内存

Sal*_*ore 1 javascript three.js

当我使用scene.remove(网格)移除网格时,我有一些问题在三j中释放内存,网格被删除但似乎没有释放从js使用的内存.

我正在使用webglrenderer和缓冲几何来测量网格和窗口.

Nik*_*kic 6

这可能是js内存使用的黑暗面.

首先尝试为对象设置原始值.

mesh.geometry.dispose();
mesh.geometry = null; // or undefined .
//also cool
delete mesh.geometry 
Run Code Online (Sandbox Code Playgroud)

另一种方式(尝试一些黑客):

 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 
Run Code Online (Sandbox Code Playgroud)

你必须确定这个对象只是他自己的一个例子(怎么说).确保你没有克隆,如果你有,你也需要摧毁他.

更新:我想再说一遍,使用slice方法从forEach或for循环中的对象清除数组.