内存泄漏有three.js和许多形状 [英] Memory leak with three.js and many shapes

查看:162
本文介绍了内存泄漏有three.js和许多形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一些很快就会耗尽内存并死掉的代码。



我已将其削减到代码的圆环生成/删除部分。我已经检查过场景数组和我的圆环阵列的长度随着形状的移除而缩小,因此它们看起来管理得很好,但我不确定内存在哪里泄漏。



任何想法?



http:// jsfiddle。 net / eVwP3 /

解决方案

webGLRenderer 之后删除网格

  scene.remove(mesh); 

你可以用



$ b <$ p来释放内存$ p> mesh.dispose();
geometry.dispose();
material.dispose();
texture.dispose();

参见 http://threejs.org/examples/webgl_test_memory.html http: //threejs.org/examples/webgl_test_memory2.html



编辑:更新为three.js r.69



PS很好的演示。您可能需要考虑创建一个对象池并重用它们,而不是不断地分配和取消分配。


I have created some code which very quickly eats up memory and dies.

I have whittled this down to the torus generation / removal sections of the code. I have checked that the length of the scene array and my torus array are shrunk as shapes are removed so they appear to be well managed, but I am not sure where the memory is leaking.

Any ideas?

http://jsfiddle.net/eVwP3/

解决方案

In webGLRenderer, after removing a mesh with

scene.remove( mesh );

you can deallocate the memory with

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

See http://threejs.org/examples/webgl_test_memory.html and http://threejs.org/examples/webgl_test_memory2.html.

EDIT: updated to three.js r.69

P.S. Nice demo. You might want to consider creating a pool of objects and reusing them, rather than continually allocating and deallocating.

这篇关于内存泄漏有three.js和许多形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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