How do I clear a scene, model, lights, materials, canvas, etc.?

When I leave babylon.js scene page, the canvas is still there and I can manipulate the scene model. How do I clear a scene, model, lights, materials, canvas, etc.?

The simplest way is to use scene.dispose() to release all resources.
As for canvas element it relates to DOM and can be removed with canvas.remove()

1 Like

Also see:

2 Likes

I tried your method and it worked very well and helped me a lot, thank you. By the way, how do you clean up the memory occupied by the scene?

I tried to find answers in the resources you provided and also found a solution that helped me a lot, thank you!

If there are no references left, Garbage Collector will do the job automatically.

I see, I see, thank you! :grin:

1 Like