Node Materials are leaking strings

We’re seeing a problem with Node Materials leaking string values from the parsed shader code.

In these two playgrounds, we can see the memory climb very quickly when we do a reload, even though the previous material is disposed.

With Reload:

Without Reload:

It’s pretty stark, but what seems to be happening is that EngineStore is retaining these strings on the Window object.

Is this a bug or are we missing a magic function to clean it up?

This is expected as we store shaders (effects) so we do not need to recompile a shader twice (as compilation is quite slow).
That being said if you do not want to waste memory for that, you can just call this:

engine.releaseEffects();
1 Like

Our actual use case is closer to this, in which we’re loading a Node Material once and then cloning so we can use it in different ways across meshes. Even with this update, I’m still seeing memory leaking.

yes you are totally right because we HAVE A FREAKING LEAK :slight_smile:

Thanks mate for the ping. I will send a PR quickly to fix that crap !

1 Like

Fix memory leak when manually disposing effects by deltakosh · Pull Request #17299 · BabylonJS/Babylon.js

1 Like

Can’t you even pretend to be slow? :wink:

Thanks so much!

ETA: using the link from the PR, it seems to have stabilized.

Any luck with reference count + delayed cleanup, or weakmap

You know what? I forgot I did ref counting for effects lol.
We are even letting one frame to make sure you are not recreating the same shader before disposing the compiledEffect.

I simply forgot about it. Man, don’t get old…

2 Likes

From our end, we can confirm that strings are no longer piling up even when we dispose the materials.

excellent news!