【问题标题】:Possible memory leak using the CanvasRenderer使用 CanvasRenderer 可能存在内存泄漏
【发布时间】:2013-12-19 07:25:16
【问题描述】:

我的应用程序出现内存泄漏。我设法将其归结为一个简单的测试用例:http://jsfiddle.net/729sv/

在场景中添加和删除几何体时,似乎存在泄漏。

当小提琴启动时,打开一个 JavaScript 控制台并单击该对象几次。注意 Three.js 的 __objectsRemoved[] 数组被打印出来并且永远不会变为 0(我认为这意味着垃圾收集器永远不会删除它们)。

以类似的方式,如果您使用 Chrome Profiles->Record Heap Allocation 功能,启动应用程序,单击几次,停止配置文件并在“mesh”上过滤,您会注意到有很多三个.Mesh 就浏览器而言仍然存在。

如果您将渲染器切换到 WebGLRenderer,这两个问题都会消失。

这是CanvasRenderer 中的错误还是我使用不正确

【问题讨论】:

    标签: javascript three.js


    【解决方案1】:

    这是 CanvasRenderer 中的一个错误。见ThreeJS garbage collection issue

    scene = new THREE.Scene();
    
    if ( renderer instanceof THREE.CanvasRenderer ) {
    
        scene.__lights = { length: 0, push: function(){}, indexOf: function (){ return -1 }, splice: function(){} }
        scene.__objectsAdded = { length: 0, push: function(){}, indexOf: function (){ return -1 }, splice: function(){} }
        scene.__objectsRemoved = { length: 0, push: function(){}, indexOf: function (){ return -1 }, splice: function(){} }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-23
      • 2020-06-12
      • 2011-07-18
      • 1970-01-01
      相关资源
      最近更新 更多