# Memory leak in babylon file loader

**URL:** <https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710>\
**Category:** Bugs\
**Created:** [May 24, 2022, 11:03pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710 "2022-05-24T23:03:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghempton](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ghempton/32/8711_2.png) [@ghempton](https://forum.babylonjs.com/u/ghempton)\
**Post date:** [May 24, 2022, 11:03pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710/1 "2022-05-24T23:03:54Z")

</div>

We have an [app](https://www.spotvirtual.com) where we construct multiple scenes and destroy them. While investigating a memory leak, I found an issue that seems that all materials loaded via the babylon file loader are stored in a global object: [Babylon.js/babylonFileLoader.ts at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Loading/Plugins/babylonFileLoader.ts#L52). These references retain the scene itself and causes big memory issues for our app.

Would it make sense to refactor this to use a WeakMap on the passed in Scene?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [May 25, 2022, 11:38am UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710/2 "2022-05-25T11:38:12Z")

</div>

Great catch!

That’s an interesting issue. having a “temp” object not clear when needed should be fixed as soon as we can.

@bghgary - do you want to take over?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 25, 2022, 3:49pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710/3 "2022-05-25T15:49:24Z")

</div>

@ghempton Nice catch !!!

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 25, 2022, 5:43pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710/4 "2022-05-25T17:43:58Z")

</div>

Here we are: [Fix memoryleak by deltakosh · Pull Request #12585 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/12585)

---

<div class="post-metadata">

**Author:** ![ghempton](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ghempton/32/8711_2.png) [@ghempton](https://forum.babylonjs.com/u/ghempton)\
**Post date:** [May 25, 2022, 5:45pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-file-loader/30710/5 "2022-05-25T17:45:03Z")

</div>

Wow you guys are fast! 🙂 Thanks for building such an awesome platform
