最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the right way to remove a mesh completely from the scene in three.js? - Stack Overflow

programmeradmin2浏览0评论

How can I remove meshes from three.js scene completely without causing memory leaks. I could find that loading the same models again and again causes the browser to crash, so it seems like the memory is not being deallocated.

How can I remove meshes from three.js scene completely without causing memory leaks. I could find that loading the same models again and again causes the browser to crash, so it seems like the memory is not being deallocated.

Share Improve this question edited Nov 20, 2016 at 6:53 the12 2,4156 gold badges20 silver badges39 bronze badges asked Nov 19, 2016 at 15:07 sreesreenusreesreenu 1,0572 gold badges12 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 17

Use the dispose method on the geometry and material. Also, ensure that nothing is holding references to these objects, as that will prevent garbage collection.

var myMesh = new THREE.Mesh(geo, mat);
scene.add(myMesh);
//...
scene.remove(myMesh);
myMesh.geometry.dispose();
myMesh.material.dispose();
myMesh = undefined;
发布评论

评论列表(0)

  1. 暂无评论