1

I use multimaterial objects in my scene, and I am wondering what is the best way to remove and dispose of them? I've read questions on how to dispose of regular objects, and they say you can use .dispose() on the object, but there is no method for multimaterial objects or for regular objects(it's not listed in the Object3D document page).

Is it enough to just dispose the geometry and materials? What do I do after that, set the object to null? Will this free up the memory? (this is my concern since I use a lot of objects and want to make sure memory is released).

.

edit: So after experimenting, It appears as if the way to dispose objects follows this sequence:

  • scene.remove(mesh);
  • mesh.geometry.dispose(); if you want to remove the geometry (looping through children of a multimaterial object and disposing all of their geometry seems to be okay)
  • mesh.geometry = undefined;
  • mesh = undefined;

If you want to remove the materials used in a multimaterial object, you can remove each one with material.dispose();

so if you initialize a material to var material = new THREE.MeshBasicMaterial();

material.dispose(); would remove it.

Then you would do material = undefined;

Textures are disposed similarly.

If I'm wrong, let me know.

user3591153
  • 409
  • 4
  • 14

0 Answers0