From 58eb314027f040014a5c196c1c0d6feb7784ba30 Mon Sep 17 00:00:00 2001 From: Noeri Huisman <8823461+mrxz@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:23:06 +0100 Subject: [PATCH 1/2] Dispose of spherical harmonics arrays and packedArray in PackedSplats --- src/PackedSplats.ts | 28 ++++++++++++++++++++++++++-- src/dyno/program.ts | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/PackedSplats.ts b/src/PackedSplats.ts index 327d3180..3a6f5325 100644 --- a/src/PackedSplats.ts +++ b/src/PackedSplats.ts @@ -12,6 +12,8 @@ import { import { DynoProgram, DynoProgramTemplate, + DynoSampler2D, + type DynoType, DynoUniform, DynoVec2, DynoVec4, @@ -241,12 +243,32 @@ export class PackedSplats { dispose() { if (this.target) { this.target.dispose(); + this.target.texture.source.data = null; this.target = null; } if (this.source) { this.source.dispose(); + this.source.source.data = null; this.source = null; } + + this.packedArray = null; + + for (const key in this.extra) { + const dyno = this.extra[key] as DynoUniform< + DynoType, + string, + THREE.Texture + >; + if (dyno instanceof DynoUniform) { + const texture = dyno.value; + if (texture?.isTexture) { + texture.dispose(); + texture.source.data = null; + } + } + } + this.extra = {}; } // Ensures that this.packedArray can fit numSplats Gsplats. If it's too small, @@ -432,7 +454,9 @@ export class PackedSplats { if (this.target && (maxSplats ?? 1) <= this.maxSplats) { return false; } - this.dispose(); + if (this.target) { + this.target.dispose(); + } const textureSize = getTextureSize(maxSplats ?? 1); const { width, height, depth } = textureSize; @@ -687,7 +711,7 @@ export class PackedSplats { static programTemplate: DynoProgramTemplate | null = null; // Cache for GsplatGenerator programs - static generatorProgram = new Map(); + static generatorProgram = new WeakMap(); // Static full-screen quad for pseudo-compute shader rendering static fullScreenQuad = new FullScreenQuad( diff --git a/src/dyno/program.ts b/src/dyno/program.ts index 97c2897f..6023a4ce 100644 --- a/src/dyno/program.ts +++ b/src/dyno/program.ts @@ -98,7 +98,7 @@ export class DynoProgramTemplate { } } -const programMaterial = new Map(); +const programMaterial = new WeakMap(); function getMaterial(program: DynoProgram): THREE.RawShaderMaterial { let material = programMaterial.get(program); From 5867904bcdd87de5f4773b6121e34adfa572b225 Mon Sep 17 00:00:00 2001 From: Noeri Huisman <8823461+mrxz@users.noreply.github.com> Date: Mon, 15 Dec 2025 16:23:36 +0100 Subject: [PATCH 2/2] Don't dispose SplatMesh instances in interactivity example --- examples/interactivity/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/interactivity/index.html b/examples/interactivity/index.html index 4b5c53ff..74303e6a 100644 --- a/examples/interactivity/index.html +++ b/examples/interactivity/index.html @@ -176,7 +176,6 @@

Food scans by Tipatat