WebGPURenderer: Dispose render objects when the renderer is disposed. - #34327
WebGPURenderer: Dispose render objects when the renderer is disposed.#34327wcandillon wants to merge 4 commits into
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Refactor `dispose()`.
Simpify code.
Clean up.
|
@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 ); |
There was a problem hiding this comment.
@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).
There was a problem hiding this comment.
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.
fixes wcandillon/react-native-webgpu#445
The issue was first reported in wcandillon/react-native-webgpu#445
Please try the file below with
?lib=cdnto 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