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

**URL:** <https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895>\
**Category:** Questions\
**Created:** [August 19, 2024, 2:52am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895 "2024-08-19T02:52:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![C-Hensin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/c-hensin/32/41057_2.png) [@C-Hensin](https://forum.babylonjs.com/u/C-Hensin)\
**Post date:** [August 19, 2024, 2:52am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/1 "2024-08-19T02:52:24Z")

</div>

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.?

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [August 19, 2024, 3:09am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/2 "2024-08-19T03:09:26Z")

</div>

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()`

---

<div class="post-metadata">

**Author:** ![HiGreg](https://avatars.discourse-cdn.com/v4/letter/h/c5a1d2/32.png) [@HiGreg](https://forum.babylonjs.com/u/HiGreg)\
**Post date:** [August 19, 2024, 3:09am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/3 "2024-08-19T03:09:53Z")

</div>

> [@Clearing the scene and engine - is this overkill?](https://forum.babylonjs.com/t/clearing-the-scene-and-engine-is-this-overkill/407/3):
>
> And btw you can just call engine.dispose() to achieve the same goal

Also see:

> [@How can I properly clean up (terminate) babylon js engine (scene)?](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558):
>
> 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?

> **[Proper way to Clear entire scene](https://www.html5gamedevs.com/topic/27615-proper-way-to-clear-entire-scene/)**
>
> I am clearing my scene entirely, where I use completely new sounds and new plans/textures. What is the proper way to do this? I'm first going through each of my planes and removing the plane and animations for each of them: item.plane.dispose();...

> [@Completely Clearing a Scene](https://forum.babylonjs.com/t/completely-clearing-a-scene/40109):
>
> As I said elsewhere, I’m trying to create more scenes for my [Merlin and Morgana](https://forum.babylonjs.com/t/merlin-and-morgana/38861) tale and that will involve deleting all my previous meshes, materials, textures and audio. On a previous attempt, some years back, I just used dispose.scene.(). Recently I found this thread from the old forum : [Proper way to Clear entire scene](https://www.html5gamedevs.com/topic/27615-proper-way-to-clear-entire-scene/). It seems that the recommended method is : scene.dispose(); engine.dispose(); as I gather it will delete all textures and audio files. Any thoughts and suggestions as th…

> [@Clearing the scene and engine - is this overkill?](https://forum.babylonjs.com/t/clearing-the-scene-and-engine-is-this-overkill/407):
>
> If I want to clear EVERYTHING to free up all the memory consumed by BabylonJS (forgetting about Chrome’s poor memory management at least…), is it enough to simply call: engine.dispose(); engine = null; Or should I try to manually dispose and set all lights/cameras/materials/meshes to null? Right now I am using this code, and wondering if it is overkill: for (let i = 0; i \< this.\_scene.cameras.length; i++) { if (this.\_scene.cameras[i] && !this.\_scene.cameras[i].isDisposed()) { this.\_scene.…

---

<div class="post-metadata">

**Author:** ![C-Hensin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/c-hensin/32/41057_2.png) [@C-Hensin](https://forum.babylonjs.com/u/C-Hensin)\
**Post date:** [August 19, 2024, 3:57am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/4 "2024-08-19T03:57:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![C-Hensin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/c-hensin/32/41057_2.png) [@C-Hensin](https://forum.babylonjs.com/u/C-Hensin)\
**Post date:** [August 19, 2024, 3:59am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/5 "2024-08-19T03:59:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [August 19, 2024, 5:03am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/6 "2024-08-19T05:03:21Z")

</div>

> [@C-Hensin](#):
>
> clean up the memory occupied by the scene?

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

---

<div class="post-metadata">

**Author:** ![C-Hensin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/c-hensin/32/41057_2.png) [@C-Hensin](https://forum.babylonjs.com/u/C-Hensin)\
**Post date:** [August 19, 2024, 6:35am UTC](https://forum.babylonjs.com/t/how-do-i-clear-a-scene-model-lights-materials-canvas-etc/52895/7 "2024-08-19T06:35:03Z")

</div>

I see, I see, thank you! 😁
