Skip to content

WebGPURenderer: Dispose render objects when the renderer is disposed. - #34327

Open
wcandillon wants to merge 4 commits into
mrdoob:devfrom
wcandillon:fix-webgpu-renderer-dispose-leak
Open

WebGPURenderer: Dispose render objects when the renderer is disposed.#34327
wcandillon wants to merge 4 commits into
mrdoob:devfrom
wcandillon:fix-webgpu-renderer-dispose-leak

Conversation

@wcandillon

@wcandillon wcandillon commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

fixes wcandillon/react-native-webgpu#445

The issue was first reported in wcandillon/react-native-webgpu#445

Please try the file below with ?lib=cdn to see the leak and against this patch to see the fix.
If there is a path to have this integrated in the test suite let me know (didn't look like there is).

repro-renderer-leak.html

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 372.43
87.92
372.43
87.92
+0 B
+0 B
WebGPU 700.29
193.21
700.46
193.23
+164 B
+29 B
WebGPU Nodes 698.28
192.9
698.45
192.93
+164 B
+28 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 515.85
124.88
515.85
124.88
+0 B
+0 B
WebGPU 774.29
207.94
774.45
207.98
+164 B
+36 B
WebGPU Nodes 723.25
195.27
723.41
195.3
+164 B
+30 B

Refactor `dispose()`.
Comment thread src/renderers/common/Renderer.js
@wcandillon

wcandillon commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@Mugen87 Thank You for looking into this so promptly ❤️ Really appreciate it. It inspires me to be a better maintainer in my own projects.


};

this._renderObjects.add( renderObject );

@Mugen87 Mugen87 Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunag The issue described in this PR is real and unfortunately there is no way around some additional management. We have to track all render objects with something we can iterate otherwise there is no way to trigger the renderObject.dispose() call.

Lingering dispose event listeners eventually block the GC so with no explicit dispose(), these listeners won't go away if module or apps keep references to objects (like the module scope geometry in QuadMesh).

@Mugen87 Mugen87 Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've added a similar tracking in Geometries via #31798 to solve the same type of problem.

I think we should consider to implement a unify way of managing dispose listeners in the renderer components. Instead of doing this per component (a quick search reveals RenderObject, Geometries, Texture, Renderer, Background and NodeManager) we could have a single registry for all internal dispose listeners and that registry is disposed of in renderer.dispose().

That would be a bigger refactoring than this PR though. So for now, it's better to merge this PR.

@Mugen87 Mugen87 added this to the r186 milestone Aug 21, 2026
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.

OOM: [RNBridgeless] reason = Max heap size was exceeded

2 participants