Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three js memory management

I have a large scene with a lot of Mesh and MorphAnimMesh. I want to free memory when the meshes are removed. If i know right this is the best way to do:

for ( var i = scene.children.length - 1; i >= 0 ; i -- ) {
  var obj = scene.children[i];
  scene.remove(obj);
  obj.deallocate(); 
  obj.geometry.deallocate();
  obj.material.deallocate();
  obj.material.map.deallocate();
}

if i check the memory usage at task manager after this, nothing changes. ( tried to wait a few min for GC but nothing. ) Google Chrome memory snapshot shows the objects still there. morphTargets in THREE.Geometry @1862203 etc.

Tried to set the obj to null, but still no memory decrease.

Any idea what am i doing wrong?

Its a game with levels and the player can change from one to another. After a few change memory usage increases to really high. Thats why i want to remove all object from memory before the level change.

like image 357
user974250 Avatar asked Dec 17 '12 13:12

user974250


1 Answers

Most likely, you need to add some, or all, of the following:

geometry.dispose();
material.dispose();
texture.dispose();

Check out these examples:

http://mrdoob.github.com/three.js/examples/webgl_test_memory.html

http://mrdoob.github.com/three.js/examples/webgl_test_memory2.html

three.js r.60

like image 127
WestLangley Avatar answered Nov 09 '22 11:11

WestLangley