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

**URL:** <https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558>\
**Category:** Questions\
**Created:** [February 13, 2020, 11:38am UTC](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558 "2020-02-13T11:38:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![miyabi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miyabi/32/6678_2.png) [@miyabi](https://forum.babylonjs.com/u/miyabi)\
**Post date:** [February 13, 2020, 11:38am UTC](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558/1 "2020-02-13T11:38:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![miyabi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miyabi/32/6678_2.png) [@miyabi](https://forum.babylonjs.com/u/miyabi)\
**Post date:** [February 13, 2020, 3:10pm UTC](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558/2 "2020-02-13T15:10:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcharnley](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcharnley/32/10228_2.png) [@jcharnley](https://forum.babylonjs.com/u/jcharnley)\
**Post date:** [November 9, 2020, 10:00am UTC](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558/3 "2020-11-09T10:00:17Z")

</div>

> [@miyabi](#):
>
> engine.dispose()

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

---

<div class="post-metadata">

**Author:** ![Hasnain\_Koser](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hasnain_koser/32/11835_2.png) [@Hasnain\_Koser](https://forum.babylonjs.com/u/Hasnain_Koser)\
**Post date:** [November 10, 2020, 4:07am UTC](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558/4 "2020-11-10T04:07:07Z")

</div>

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](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/22fa696d32b0f7d281b094cb8294caab8deb8de9.png)

Next I give this a value in the create scene function -  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/a/a553450b614a653dfc27687d2238814e2fe5cc0b.png)

and finally if a condition is met I dispose of the scene -  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/b/b11c8ae66860efcdf178b1ac2cc1f00553ed65e6.png)

---

<div class="post-metadata">

**Author:** ![jcharnley](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcharnley/32/10228_2.png) [@jcharnley](https://forum.babylonjs.com/u/jcharnley)\
**Post date:** [November 10, 2020, 12:29pm UTC](https://forum.babylonjs.com/t/how-can-i-properly-clean-up-terminate-babylon-js-engine-scene/8558/5 "2020-11-10T12:29:12Z")

</div>

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
