From f2f6d4ff49b6cd3923216c05d75600ba1a1544fa Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Sun, 5 Jul 2026 13:44:04 -0500 Subject: [PATCH] add persistent count for the number of model users to unload only when uses drops to 0 --- packages/website/src/hooks/useDispose.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/website/src/hooks/useDispose.ts b/packages/website/src/hooks/useDispose.ts index 2ff4e3685..5acc7a6ea 100644 --- a/packages/website/src/hooks/useDispose.ts +++ b/packages/website/src/hooks/useDispose.ts @@ -3,9 +3,19 @@ import { useEffect } from "react"; import { Cache, Group, Mesh, MeshStandardMaterial, Object3D } from "three"; import { GLTFLoader, type GLTF } from "three-stdlib"; +const users: Record = {}; + export function useDispose(gltf: GLTF & ObjectMap, path: string) { useEffect(() => { + if (path in users) { + users[path]++; + } else { + users[path] = 1; + } + return () => { + if (--users[path] > 0) return; + gltf.scene.traverse((object) => { if (object instanceof Mesh) { if (object.material instanceof MeshStandardMaterial) {