Disposing of loaded assets

I was trying to setup a playground to demo loading of glb files into an SPS and then disposing and loading a new one.

It turns out it’s quite complex to avoid leaving stray textures etc. in memory.

Unless I’m missing some really obvious much simpler way to do it. This is what I have so far.

Use the Load Model A / Load Model B buttons to toggle between models.

You can see from the code it’s not what I’d call straight forward. My first several attempts always left a memory leak.

Is there a better way to do this?

1 Like

This kind of basic code should work https://playground.babylonjs.com/#WGZLGJ#11446 to delete the hierarchy with associated materials and textures.

Otherwise you could check asset containers so that you can track all the loaded pieces easily.