Skip to content

Conversation

@WHOIM1205
Copy link
Contributor

Description

I'm submitting this fix to address a critical WebGL memory leak observed during GLTF geometry loading in the event display.

Currently, whenever a GLTF geometry is loaded (for example when switching between detector views or reloading the same detector), the import logic clones and transforms multiple geometries before merging them. While the merged geometry is rendered correctly, the intermediate cloned geometries are never disposed, leading to unbounded GPU memory growth over time.


The Issue

The root cause is that intermediate BufferGeometry objects created during GLTF loading are never explicitly disposed.

  • The behaviour:
    Each call to loadGLTFGeometry() clones multiple geometries using geometry.clone().applyMatrix4() and stores them temporarily for merging.

  • The result:
    mergeGeometries() creates a new merged geometry, but the original cloned geometries remain allocated in WebGL memory.

  • Why it matters:
    WebGL buffers are not freed by JavaScript garbage collection. Repeated geometry loads progressively increase GPU memory usage, eventually causing WebGL context loss, browser crashes, or severe performance degradation during long sessions.


The Fix

I updated the GLTF import logic to explicitly dispose all intermediate cloned geometries immediately after they are merged.

After BufferGeometryUtils.mergeGeometries() completes and the merged mesh is added to the scene, all temporary BufferGeometry instances used as merge inputs are now cleaned up using dispose().

This ensures that GPU memory is released correctly while keeping rendering behavior unchanged.


Verification

You can verify this fix using browser DevTools:

  1. Load a large GLTF detector geometry.
  2. Open GPU or memory monitoring tools in the browser.
  3. Clear and reload the geometry multiple times.
  4. Result: GPU memory usage remains stable and does not increase with each reload.

Signed-off-by: WHOIM1205 <rathourprateek8@gmail.com>
@WHOIM1205 WHOIM1205 force-pushed the fix/webgl-gltf-geometry-memory-leak branch from 6b16bd5 to c50d18b Compare January 25, 2026 19:52
@WHOIM1205
Copy link
Contributor Author

hey @EdwardMoyse
the PR fixes a silent WebGL memory leak during GLTF loading. Happy to address any feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant