I struggled with this issue for a while, reaching out to Chrome and Three.js with bug reports but finding no solution.
It appears that memory was not being released even after an extended period of time, indicating that something was still referencing the memory block and preventing the garbage collector from freeing it up.
Fortunately, I discovered a workaround that proved effective for me:
- Start by creating an array to store all items added to the scene.
- Whenever you add a new item to the scene, be sure to also add it to this array.
- When it's time to destroy an item, use `scene.remove('item name')` to remove it from the scene.
- Finally, iterate through the array and manually set all items to undefined.
By following this approach, I successfully reclaimed over 600MB of RAM from my Three.js scene.
UPDATE:
In response to Mr. Doob and WestLangley's suggestion in this thread about memory leaks in Three.js when handling numerous shapes, I have yet to test their advice with my own code.
If you are using WebGLRenderer, consider adding the following steps after removing a mesh with `scene.remove( mesh )`:
- Deallocte the memory with `renderer.deallocateObject( mesh );`
- You can also deallocate textures with `renderer.deallocateTexture( texture );`