- removeScene = () = >{
- this.clearScene();
- };
- clearCache = item = >{
- item.geometry.dispose();
- item.material.dispose();
- };
- clearScene = () = >{
- this.removeObj(this.scene);
- };
- removeObj = obj = >{
- let arr = obj.children.filter(x = >x);
- arr.forEach(item = >{
- if (item.children.length) {
- this.removeObj(item);
- } else {
- this.clearCache(item);
- item.clear();
- }
- });
- obj.clear();
- arr = null;
- };
- destroyed = () = >{
- window.removeEventListener(“resize”, this.onWindowResize);
- this.clearScene();
- this.renderer.renderLists.dispose();
- this.renderer.dispose();
- this.renderer.forceContextLoss();
- this.renderer.domElement = null;
- this.renderer.content = null;
- this.renderer = null;
- cancelAnimationFrame(animationId);
- THREE.Cache.clear();
- };
本文链接地址: threejs释放内存