Free an Array of Synths?

Hi there -
I am trying to understand how to manage synths a little better, but I’m a little confused about something.

I can collect 10 sine wave generators an array.
~array = 10.collect{{, 0, 0.1)}.play};

But, in order to free them all, do I need to iterate through the list and take them out one-by-one, like this?{|x|;

Even if I do this, my ~array still has all of these items in it. So, do I also need this at the end, in order to start again with a clean slate?
~array = [];

Thanks in advance for the clarification.

Yes, that’s correct. Sc has no concept of a destructor so the disconnected server representation will always hang around. That being said, you can just override them with new synths.

1 Like

Alternatively, you can put Synths into a group and free / release the whole group. That’s practical in many contexts, maybe overcomplicated here. You can also use partial application:

Other than that, you can take also produce the multitude of SinOscs inside the SynthDef and sum or mix to stereo with Splay.

1 Like

I often use a List instead of an Array, which allows you to ~list.pop.stop one or all of your Synths, and the size of the List will stay aligned with how many Synths are in it. To stop and remove them all, use{ ~list.pop.stop }.

EDIT: Just to clarify, I was using .stop here because these were Pbinds, but you would use .free for Synths!

1 Like