内存泄漏与 Three.js 和许多形状 [英] Memory leak with three.js and many shapes
问题描述
我创建了一些代码,这些代码很快就会耗尽内存并死掉.
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.
有什么想法吗?
推荐答案
在webGLRenderer
中,用
scene.remove( mesh );
你可以用
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
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屋!