How can I properly clean up (terminate) babylon js engine (scene)?

I tried deleting engine obj like delete engine, but it seems to keep using CPU and memory.

I might make some mistake here, so would you show me how you clean up Babylon scene in your web app or something?

Simply calling engine.dispose() before setting engine to null works well!

3 Likes

anyone got a illustration of dispose working outside of scene? been trying but struggling

make a variable outside the function although do not give it a value. When you want to dispose of the scene just do scene.dispose, something like this -

here I create the scene variable -
image

Next I give this a value in the create scene function -
image

and finally if a condition is met I dispose of the scene -
image

Thanks for that, I kinda have something working but loading in another model stores some memory functionality in there that messes up the new scene. I’ll try do a PG today but will be difficult as I convert the model to base64 way before I setup the scene