I’m currently (still after years) in the process of building a game and right now tinkering with the idea of re-initializing the entire renderer when changing levels. Each level consists of “components” and a wide assortment of meshes, materials, etc. with some of them being unique to that level.
For as long as I can remember working with Three, there have been several questions about “how to properly dispose of objects”. Textures or geometries may reside in memory after an object has been removed from the scene. This made me wonder if it would be feasible to just re-initialize (recreate) the WebGLRenderer every time a level will load? The average time the player spends in one level varies from a couple of seconds to a few minutes tops.
Right now every component in my engine has a
dispose() method and it is each components’ own responsibility to clean up/dispose of every resource it allocated, either geometry, materials, or other things unrelated to the renderer.
I’m wondering how you would approach this situation? Would it be safer (avoiding accidental memory-leaks) to just re-initialize the WebGLRenderer every time a level loads, or is meticulously disposing of every resource manually really the way to go? I’m already pretty far into development, and its a pretty big refactor to change the current behavior of disposing everything one-by-one.
Since I’m unsure of the caveats of either method, I’m really interested in your thoughts about this and especially the reasoning behind it.