I use a combined class for Mesh and SkinnedMesh, to attach or detach a skeleton or to reuse it from an object pool without dumping every old and spawning new meshes.
While it works assigning another geometry, i wonder if i have to delete references somewhere (mesh-geometry relation lookups maybe), or if it’s memoryleak-free. I just found older posts around this topic, maybe this isn’t even a issue anymore.
Because geometries get cached inside the renderer, you should always call geometry.dispose() if you delete/free an instance of Geometry or BufferGeometry.
But the geometries aren’t deleted at this time, just changed to another, it’s not a generated only used once. Or does it free kinda references i mentioned?
Basically when a asset is assigned it just sets the geometry property of the mesh, when i replace the asset (for example to customize a character), i assign the geometry and call a method which does THREE.Mesh or THREE.SkinnedMesh constructor specific things, that’s all.
Now my concerns are that there are for example mesh.uuid+geometry.uuid stored references in the renderer or properties that will be stored for skeleton animations, since the mesh object won’t be dropped, but use a different geometry.
I think you’re not understanding the answer or we don’t understand the question without code. Geometry basically ends up being stored in two places. In your main memory once you construct say a BufferGeometry and fill it with data, and on the GPU, once the WebGLRenderer.render() encounters a node in the scene graph for the first time using that geometry. If you don’t call dispose, this will remain forever on the GPU.
If we remove a Mesh from a scene graph, then create a new Mesh and do mesh.geometry = theSameGeometryAsBefore on this new Mesh so that the new Mesh has the same geometry instance as the previous Mesh, do we need to call dispose() on the geometry?
If there isn’t anything in the renderer that associates geometry with meshes, then the answer will be that we don’t (i.e. if dispose() is only for clearing the GPU of the geometry data, then it makes sense we don’t need to dispose, and that the geometry will be transformed based on whichever mesh it is encountered on, and that any number of meshes can use the same geometry instance).
I guess his question is similar to the one i asked. If there are references or anything stored in the relation of mesh with geometry, like for caching purposes.
@mrdoob Why does .dispose() need to be called when assigning a geometry to another Mesh?
EDIT: I looked at WebGLGeometries#onGeometryDispose and I only see that it removes the Geometry from the WebGLGeometries list, and removes gl attributes. I’m not yet seeing why .dispose() is needed when assigning a Geometry to another Mesh.
Because the WebGLRenderer uploads that geometry to the GPU. You need to notify the system, somehow, that you don’t need that geometry on the GPU anymore.