Skip to content

fix: dispose variable ShaderMaterials in GPUComputationRenderer.dispose()#428

Open
madisonrickert wants to merge 1 commit intopmndrs:mainfrom
madisonrickert:fix/gpu-computation-renderer-dispose-leak
Open

fix: dispose variable ShaderMaterials in GPUComputationRenderer.dispose()#428
madisonrickert wants to merge 1 commit intopmndrs:mainfrom
madisonrickert:fix/gpu-computation-renderer-dispose-leak

Conversation

@madisonrickert
Copy link
Copy Markdown

@madisonrickert madisonrickert commented Apr 2, 2026

Summary

GPUComputationRenderer.dispose() disposes render targets and the pass-through shader material (mesh.material), but never disposes the ShaderMaterial instances created for each computation variable.

These materials are allocated in createShaderMaterial() (called from addVariable()) and stored on variable.material, but dispose() only calls mesh.material.dispose() — which is the passThruShader, not the per-variable materials. The variable ShaderMaterial objects and their associated WebGL programs are never released.

Fix

One line: variable.material.dispose() inside the existing variable loop.

How I found this

I work on a project that uses GPUComputationRenderer for a GPU-computed wave simulation. The app has a router that creates and destroys renderer instances on navigation. After switching between views repeatedly, GPU memory climbed steadily — the undisposed variable ShaderMaterial objects were accumulating.

…se()

ShaderMaterials created by createShaderMaterial() for each variable are
stored in variable.material but never disposed. The existing
mesh.material.dispose() call only disposes the passThruShader, not the
per-variable materials. This leaks WebGL programs on every teardown.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Apr 2, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

madisonrickert added a commit to madisonrickert/three.js that referenced this pull request Apr 2, 2026
…se()

ShaderMaterials created by createShaderMaterial() for each variable are
stored in variable.material but never disposed. The existing
quad.dispose() call disposes the passThruShader via the mesh, but the
per-variable materials and their WebGL programs are never released.

Same fix submitted to three-stdlib: pmndrs/three-stdlib#428

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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