Correctly remove mesh from scene and dispose material and geometry

Execute this code once and not three times in a row. This will save some overhead. Do it like so:

const object = scene.getObjectByProperty( 'uuid', i );

object.geometry.dispose();
object.material.dispose();
scene.remove( object );

The order of the last three statements does actually not matter.

Does the memory leak disappear if you execute the following code after removing the cells?

renderer.renderLists.dispose();
7 Likes