Memory leak with three.js and many shapes

前端 未结 1 616
长发绾君心
长发绾君心 2020-12-15 15:01

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

相关标签:
1条回答
  • 2020-12-15 15:21

    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.

    0 讨论(0)
提交回复
热议问题