javascript - 使用 threejs 释放内存

标签 javascript three.js

当我使用 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/

相关文章:

javascript - 如果有多个 View 依赖于它,何时销毁我的模型

javascript - 在 Three.js 中控制自定义几何图形的缩放

javascript - 如何在 Three.js 中导入 VRML 文件?

three.js - three.js如何使用背景的渐变色

three.js - 从远处看,三个 JS 纹理像素化

javascript - 通过不同的组件/页面访问数组数据

javascript - 通过 JavaScript 使用麦克风

javascript - Angularjs 以各种形式动态添加表单字段

javascript - 如何自定义OpenERP 6.1 WebClient HTML DOM?

javascript - 具有功能的 A 帧检查变量并根据值显示不同的 gltf