Disposing OBJLoader and MTLLoader

I’m wondering if there is any special consideration needed for disposing OBJLoaders or MTLLoaders once finished using them.

Is it enough to call dispose on the geometry and material properties of the renderables created with OBJLoader and MTLLoader?

I’m assuming it is possible to use a single MTLLoader and share the material across many meshes. Once we’re done with all meshes, seems like we a dispose() method on MTLLoader could be useful. What about OBJLoader, can we re-use OBJs across many instances? etc?

I don’t think a dispose method makes sense for loaders. If you free the references to the instances of OBJloader and MTLLoader, the GC can remove the related stuff from memory.

If we’re done with the scene, and just let go of everything, I think that’s true. But maybe if we’re done with the OBJ and MTL resources, but we will keep rendering other stuff in the scene, it makes sense to dispose the geometries and materials contained inside the loaders so that they release memory from the GPU?

I suppose that if we have Mesh objects referencing the geometries and materials of the loaders, it would be enough if we call dispose on the .geometry and .material props of the Meshes.

Imagine, for example, we have multiple components that are responsible for making Meshes, and these meshes use the resources of some other component that provides them from loaders. The components consuming the resources would not know when to dispose the resources, but the provider component would (in the design I’m imagining at the moment).

I just want to make sure I’m cleaning up well. I’ve got React components that mount and unmount, and it is surprisingly easy to leak memory (from what I see in the devtools).