Proper cleanup (dispose) of InstancedMesh.instanceMatrix

How should one properly dispose the InstancedMesh?

The InstanceMesh class contains an instanceMatrix. This attribute is not part of the geometry, therefore when doing geometry.dispose() as usual it will not be affected.

How should I dispose this attribute (and instanceColor when applicable) properly once some InstancedMesh ceases to be used in the scene, to prevent it lingering in the WebGLAttributes.buffers indefinitely?

It’s currently not possible to free the buffer for instanceMatrix and possibly for instanceColor since individual buffer attributes can’t be disposed. I have once filed a PR to address this issue but unfortunately it was not merged.

I suggest you comment at this PR to highlight this issue.

Until a proper support is added, I think a low-level workaround which should be possible to use is:


The PR seems to be closed already. Should I still comment on it? Or if you plan to create a new one - I will be happy to comment there.

I do not vote to expose even more internals such as attributes. It has turned out that this is not good for the maintainability and robustness of the renderer.

Yep, that’s fine