I’ve opened a couple threads on cleaning things up:
- How to completely clean up a Three.js scene from a web app once the scene is no longer needed
- Disposing OBJLoader and MTLLoader
But my thought is that in general the Three.js docs need a “How to clean things up” section, as it isn’t totally clear when/how to do it, and when not to do it. It’s easy to miss it, and perhaps leak.
So, just jotting down some ideas:
In this section, it’d be nice if it can talk about patterns (f.e. when to clean up), not just how. F.e.
- Make a texture, keep track of all instances that use it, call dispose when you have no more instances using it. (code example here)
- similar with materials
- similar with geometries
Also, not just when to clean up, but when not to clean up. F.e.
- Using an MTLLoader, don’t just dispose every material of each Mesh you no longer need if they share the same material, otherwise this cost CPU time to unload the material only to have it re-loaded by the renderer on the next render.