三js内存管理 [英] Three js memory management

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

问题描述

我有一个包含大量Mesh和MorphAnimMesh的大场景。我想在删除网格时释放内存。如果我知道这是最好的方法:

I have a large scene with a lot of Mesh and MorphAnimMesh. I want to free memory when the meshes are removed. If i know right this is the best way to do:

for ( var i = scene.children.length - 1; i >= 0 ; i -- ) {
  var obj = scene.children[i];
  scene.remove(obj);
  obj.deallocate(); 
  obj.geometry.deallocate();
  obj.material.deallocate();
  obj.material.map.deallocate();
}

如果我在此之后检查任务管理器的内存使用情况,则不会发生任何变化。 (尝试等待几分钟没有GC。)谷歌Chrome内存快照显示仍然存在的对象。 THREE.Geometry @ 1862203等中的morphTargets

if i check the memory usage at task manager after this, nothing changes. ( tried to wait a few min for GC but nothing. ) Google Chrome memory snapshot shows the objects still there. morphTargets in THREE.Geometry @1862203 etc.

尝试将obj设置为null,但仍然没有内存减少。

Tried to set the obj to null, but still no memory decrease.

任何想法我做错了什么?

Any idea what am i doing wrong?

这是一款有关等级的游戏,玩家可以从一个改变到另一个。经过几次更改后,内存使用量增加到很高。这就是为什么我想在级别更改之前从内存中删除所有对象。

Its a game with levels and the player can change from one to another. After a few change memory usage increases to really high. Thats why i want to remove all object from memory before the level change.

推荐答案

很可能,你需要添加一些,或者全部,以下内容:

Most likely, you need to add some, or all, of the following:

geometry.dispose();
material.dispose();
texture.dispose();

查看以下示例:

< a href =http://mrdoob.github.com/three.js/examples/webgl_test_memory.html =noreferrer> http://mrdoob.github.com/three.js/examples/webgl_test_memory.html

http ://mrdoob.github.com/three.js/examples/webgl_test_memory2.html

three.js r.60

three.js r.60

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

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