Reputation: 437
I try to optimize my threejs scene, (high increasing CPU usage even if the scene is not used).
I read lot of solutions and i try to remove memory of mesh with dispose()
(try to avoid memory leaks)
labelMesh[i].geometry.dispose();
labelMesh[i].material.dispose();
But when i inspect the Javascript Profiler, dispose()
increase 2 times CPU of GC.
I keep this solution or no ? What is a best option ?
Upvotes: 3
Views: 789
Reputation: 31036
I keep this solution or no ? What is a best option ?
Using .dispose()
is definitely recommended. There is actually an official guide about this topic:
https://threejs.org/docs/index.html#manual/en/introduction/How-to-dispose-of-objects.
However, there is still an issue that impedes three.js
to free resources even when .dispose()
is correctly called (see https://github.com/mrdoob/three.js/issues/12447). This happens because three.js
's internal render lists still hold references to certain objects. Calling .dispose()
will free GPU memory but not CPU memory because of these hidden references.
A workaround for this is to call renderer.renderLists.dispose()
.
three.js R107
Upvotes: 4