LinesMesh no longer disposes shaderMaterial by default — causes memory leak in BoundingBoxGizmo

Hello!
It looks like some recent changes to LinesMesh have affected how shaderMaterial is handled. Specifically, the shaderMaterial is no longer disposed automatically when the mesh is disposed.

This leads to a memory leak in BoundingBoxGizmo, which creates and disposes line meshes. Since the associated shaderMaterial isn’t cleaned up, it accumulates over time.

I’m not sure whether this should be fixed in LinesMesh or in BoundingBoxGizmo, but this behavior definitely feels unintended.

You can reproduce the issue in this Playground (check the console logs):
:link: https://playground.babylonjs.com/#SG9ZZB#39

Totally a bug, I ll push a change ASAP still wondering where the fix fits best as you mentionned

2 Likes

Hi @sebavan,
Your PR fixed issues with line mesh materials. But I still see a material leak in BoundingBoxGizmo. Please check console logs in the playground: https://playground.babylonjs.com/#SG9ZZB#41

Let me add @Cedric regarding the gizmo :slight_smile:

3 Likes