当我使用 scene.remove(mesh) 删除网格时,我在 threejs 中释放内存时遇到一些问题,网格已删除,但似乎未释放从 js 使用的内存。
我正在使用带有 buffergeometry 的 webglrenderer 来处理网格和窗口。
最佳答案
这可能是 js 内存使用的阴暗面。
首先尝试为您的对象设置原始值。
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
另一种方式(尝试一些 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
你必须确定这个对象只是他自己的实例(怎么说)。确保你没有克隆人,如果你有的话,你也需要摧毁他。
更新:我想多说一点,在forEach或for循环中使用slice方法从对象中清除数组。
关于javascript - 使用 threejs 释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39904976/