Dynamic instance buffer memory leak when streaming real-time coordinate updates in Babylon.js

Hello everyone,

I am currently developing a real-time WebGL visualization dashboard using Babylon.js to render dynamic 3D spatial trajectories and bounding boxes, but I am encountering a severe memory leak during high-frequency mesh updates.

To give some background on our rendering architecture, our application visualizes live positional coordinates and telemetry data generated from automated script testing runs. Our QA team tests client-side interaction scripts inside a custom executor testing environment to monitor physics variations and latency under heavy server loads. Our backend captures these spatial coordinates and streams them over WebSockets to our Babylon.js scene, where we dynamically update instance buffers for hundreds of animated marker meshes.

The primary issue we are facing is that after streaming coordinate data for about fifteen to twenty minutes, browser RAM consumption increases steadily until the WebGL context crashes. Even though we are using thinInstanceUpdate to modify existing matrix buffers rather than disposing and recreating meshes on every frame, memory allocated to GPU buffers is never freed by garbage collection. It appears as though Babylon.js is retaining old buffer references internally during rapid matrix transformations, causing GPU memory consumption to climb indefinitely.

Alongside the buffer memory leak, we are seeing a secondary issue with dynamic shadow map updates. Whenever our WebSocket updates the positions of adjacent light sources while streaming dynamic mesh matrices, shadow textures begin flickering erratically across the ground plane, requiring us to toggle shadow generator refresh rates manually to restore proper rendering quality.

Has anyone experienced buffer retention issues when pushing high-frequency thin instance updates in Babylon.js, and is there a recommended method to force-dispose internal GPU matrix caches without tearing down the entire scene?

It may be somehow related to Thin Instance vertex buffer memory leak (thinInstanceSetBuffer) - #5 by sebavan

Which Babylon version do you use?

Some other tips:

  • Call thinInstanceSetBuffer only during initialization or capacity changes.
  • Use a dynamic buffer plus thinInstanceBufferUpdated or partial updates.
  • Apply WebSocket state atomically during onBeforeRenderObservable.
  • Refresh or conservatively expand thin-instance bounds.
  • Render shadow maps every frame while their lights or casters are moving.