speedwell
speedwell

Reputation: 655

Possible memory leak using the CanvasRenderer

I am experiencing a memory leak in my application. I managed to boil it down to a simple test case here: http://jsfiddle.net/729sv/

When adding and removing geometry from a scene, there appears to be a leak.

When the fiddle starts, open a JavaScript console and click on the object a few times. Note the Three.js __objectsRemoved[] array is printed and never goes to 0 (I think this means the garbage collector never removes them).

In a similar fashion, if you use the Chrome Profiles->Record Heap Allocation feature, start the app, click a few times, stop the profile and filter on 'mesh', you'll notice that there are lots of THREE.Mesh's still around as far as the browser is concerned.

If you switch the renderer to a WebGLRenderer both of these issues go away.

Is this a bug in the CanvasRenderer or am I using it incorrectly

Upvotes: 0

Views: 145

Answers (1)

Kenneth Ito
Kenneth Ito

Reputation: 5261

This is a bug in the CanvasRenderer. See 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(){} }

}

Upvotes: 2

Related Questions