# Memory leak in Babylon React Native app - Engine.\_renderLoop()

**URL:** <https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648>\
**Category:** Questions\
**Tags:** babylon-native\
**Created:** [April 5, 2023, 9:51pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648 "2023-04-05T21:51:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 5, 2023, 9:51pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/1 "2023-04-05T21:51:42Z")

</div>

[@BabylonNative](https://forum.babylonjs.com/groups/babylonnative)

Our Babylon React Native Android app’s performance slowly degrades over time until the app crashes. Initial investigations suggest a memory leak from Engine.\_renderLoop() as the performance degradation occurs despite no new geometry or shaders being added to the scene. The user can simply be occasionally rotating, panning and zooming the `ArcRotateCamera` around the scene and the frame rate falls.

Unsure if it’s an issue with our code or that of Babylon.js or Babylon Native. I’ve yet to replicate this in a simpler app.

Does anyone on the Babylon Native team have any advice on how we can better investigate this to narrow down the issue?

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [April 5, 2023, 10:42pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/2 "2023-04-05T22:42:44Z")

</div>

I guess you need a profiler. If you are using React Native with JSC, I don’t believe it is possible to profile JSC on Android, but it should be possible on iOS. If you are targeting Hermes, then it should be possible on Android or iOS but I’ve never tried it myself. Otherwise, adding code to time the render loop and slowly change the code to drill into the slow parts is likely your best bet. Does the same slowness happen with the Playground app for Babylon React Native?

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 5, 2023, 11:07pm UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/3 "2023-04-05T23:07:45Z")

</div>

We’ve done some profiling with Flipper on Android, which is what helped us to identify `_renderLoop()` but I guess we need to do more investigation.

We’re using V8 on Android. We do also test on iOS but we’ve yet to confirm if the issue is evident on that platform also.

I’ll try to replicate the issue in the Playground App and get back to you as soon as I can.

I just wanted to reach out now in case there was any known issue you were aware of.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [April 6, 2023, 11:27am UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/4 "2023-04-06T11:27:46Z")

</div>

Do you repro with BabylonNative alone? if it happens in `Engine._renderLoop()` then it should also be visible in BN alone. It makes debugging easier. Moreover, with ChromeDevTools and V8, you should be able to do memory snapshots.

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 7, 2023, 12:12am UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/5 "2023-04-07T00:12:10Z")

</div>

Thanks @Cedric. I’ll give it a try.

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 11, 2023, 1:17am UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/6 "2023-04-11T01:17:59Z")

</div>

@Cedric @bghgary most of the memory use seems to be in `bindBuffers` and I found this open issue [Improve Vertex Buffer Binding · Issue #361 · BabylonJS/BabylonNative · GitHub](https://github.com/BabylonJS/BabylonNative/issues/361)

Could it be related?

I’m still investigating and trying to replicate in a small use case.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [April 11, 2023, 7:54am UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/7 "2023-04-11T07:54:46Z")

</div>

Hard to say. Do you create/recreate vertex buffers in your app? Like updating meshes

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 12, 2023, 4:28am UTC](https://forum.babylonjs.com/t/memory-leak-in-babylon-react-native-app-engine-renderloop/39648/8 "2023-04-12T04:28:57Z")

</div>

What I’m seeing at the moment is the issue seems to be isolated to V8 JIT (version 10.100.1). When I switch to either JavaScriptCore or Hermes I see no evidence of a memory leak, plus the debugging and profiling options for Hermes are a lot better. V8 JIT is better for intensive data processing though, which is one of our requirements. I’ll try updating the V8 version …
