I myself was concerned about this issue for a long time, I raised error messages using chrome and Three.js, but could not find a solution.
For some reason, the memory is not freed even after a long time, and it seems that something continues to point to the memory block, and therefore the garbage collector never frees it.
However, here is what helped
- Create an array that will contain all the elements added to the scene.
- When you add an additional element to the scene, add it to this array.
- In kill mode, run scene.remove ('item name') to remove them from the scene.
- Now iterate over the array and manually make all the elements undefined.
After that, I was able to get more than 600 MB of RAM from the Three.js scene.
update
The answer to this question is Mr. Doob and WestLangley Memory leak with three .js and many shapes , I still have to check it with my code.
In webGLRenderer after deleting the grid with
scene.remove( mesh ) ,
you can free memory with
renderer.deallocateObject( mesh );
You can free the texture with
renderer.deallocateTexture( texture );
source share