用threejs释放内存 [英] Freeing memory with threejs

查看:166
本文介绍了用threejs释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用scene.remove(mesh)删除网格时,我在threejs中释放内存时遇到了一些问题,网格被删除,但js使用的内存似乎没有释放.

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.

我将 webglrenderer 与网格和窗口的缓冲区几何一起使用.

I'm using webglrenderer with buffergeometry for the mesh and windows.

推荐答案

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

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 

另一种方式(尝试一些hack):

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.

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

Update : I want to say one more , use slice method for clearing arrays from object in forEach or for loop.

这篇关于用threejs释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆