# About the Memory Leakage Problem of Babylonjs

**URL:** <https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436>\
**Category:** Bugs\
**Created:** [March 29, 2023, 7:06am UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436 "2023-03-29T07:06:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhang](https://avatars.discourse-cdn.com/v4/letter/z/aeb1de/32.png) [@zhang](https://forum.babylonjs.com/u/zhang)\
**Post date:** [March 29, 2023, 7:06am UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436/1 "2023-03-29T07:06:46Z")

</div>

As early as version 4.0, I have discovered that there is a memory leak problem, but now using version 5.0 still exists; But at the time, I couldn’t reproduce this error in Playground. The following is a snapshot of browser memory that I captured:

 ![at first](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/e/7/e751f82a39e9413502f8b1db5dc6aed553d84d5b.png)  
 ![later](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/2/b25e27119ab7b0c6ea91cc77005a4f304f1fface.png)  
 ![Infinitely growing objects](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/5/c56197f9a892c43b3a33a1b12af76bf6078710ef.png)

As long as I annotate this line, there will be no memory leak issues.  
 ![cause](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/8/084c1dc3b37d8befecc6d5c57b6598a6204c7a87.png)。

Obviously, it is caused by self luminescence。  
I suspect that it is caused by self illumination and a large number of instances in the scene. There seems to be a conflict between them.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [March 29, 2023, 9:57am UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436/2 "2023-03-29T09:57:06Z")

</div>

Have you tried with the latest version? I know that we have fixed a number of memory leaks since the release of version 5.0.

---

<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:** [March 29, 2023, 10:57am UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436/3 "2023-03-29T10:57:12Z")

</div>

It will be great to reproduce this in the playground, or in a deployed code where babylon is separable from the rest of the code.  
Looking at the code, there is no reason not to clear this object when a mesh is disposed and it will probably fix the issue. However, the visibleInstances object is, in general, “self cleaning”, so it should be empty when the mesh is disposed unless certain conditions apply. Which might be the case when you turn on glow layer.

---

<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:** [March 29, 2023, 11:11am UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436/4 "2023-03-29T11:11:46Z")

</div>

This was created as draft - [Clear internal instance containers in Mesh when disposed by RaananW · Pull Request #13685 · BabylonJS/Babylon.js (github.com)](https://github.com/BabylonJS/Babylon.js/pull/13685), which should fix the issue in your case.

---

<div class="post-metadata">

**Author:** ![zhang](https://avatars.discourse-cdn.com/v4/letter/z/aeb1de/32.png) [@zhang](https://forum.babylonjs.com/u/zhang)\
**Post date:** [March 29, 2023, 11:45am UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436/5 "2023-03-29T11:45:53Z")

</div>

I will try.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [April 27, 2023, 3:45pm UTC](https://forum.babylonjs.com/t/about-the-memory-leakage-problem-of-babylonjs/39436/6 "2023-04-27T15:45:38Z")

</div>

Hi! @zhang have you had a chance to test 6.0 and see if the memory problems have gone?
