From 22807b383374b8ba3cb1048c0615252ceb2c803f Mon Sep 17 00:00:00 2001 From: Aria Date: Fri, 14 Nov 2025 16:05:09 -0600 Subject: [PATCH] Use weak references for sound sources --- packages/superdough/superdough.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/superdough/superdough.mjs b/packages/superdough/superdough.mjs index b59e3ae05..4827ffbd3 100644 --- a/packages/superdough/superdough.mjs +++ b/packages/superdough/superdough.mjs @@ -481,7 +481,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) // oldest audio nodes will be destroyed if maximum polyphony is exceeded for (let i = 0; i <= activeSoundSources.size - maxPolyphony; i++) { const ch = activeSoundSources.entries().next(); - const source = ch.value[1]; + const source = ch.value[1].deref(); const chainID = ch.value[0]; const endTime = t + 0.25; source?.node?.gain?.linearRampToValueAtTime(0, endTime); @@ -513,7 +513,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) if (soundHandle) { sourceNode = soundHandle.node; - activeSoundSources.set(chainID, soundHandle); + activeSoundSources.set(chainID, new WeakRef(soundHandle)); // allow GC } } else { throw new Error(`sound ${s} not found! Is it loaded?`);