From b51b5691ed01cad863006f58e0ba3fb32b67a330 Mon Sep 17 00:00:00 2001 From: kevinstadler Date: Thu, 21 Sep 2023 13:24:00 +0200 Subject: [PATCH] Disconnect all parts of stopped output units individually. This allows them to be properly removed from the JSyn synth network, and consequently garbage collected. This should close #74. Insert COPIOUS expletives here. --- src/processing/sound/Engine.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/processing/sound/Engine.java b/src/processing/sound/Engine.java index c6a8df5..dfc438c 100644 --- a/src/processing/sound/Engine.java +++ b/src/processing/sound/Engine.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.stream.IntStream; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; @@ -409,7 +410,11 @@ protected void play(UnitSource source) { protected void stop(UnitSource source) { if (this.addedUnits.contains(source.getUnitGenerator())) { - source.getOutput().disconnectAll(); + // this is usually just the two-part output of a JSynCircuit, but let's + // keep it generic just in case + for (int i : IntStream.range(0, source.getOutput().getNumParts()).toArray()) { + source.getOutput().disconnectAll(i); + } this.remove(source.getUnitGenerator()); } }