home/ atoms/ sc-envelope-doneaction

Setting doneAction:2 in an envelope automatically frees a Synth when the envelope finishes

In SuperCollider, a Synth keeps running until explicitly freed, even after its sound has ended. EnvGen’s doneAction argument controls what happens when the envelope reaches its last segment. doneAction:2 tells the server to deallocate the Synth node automatically — preventing accumulation of silent, CPU-wasting processes. This is essential when spawning many short-lived Synths (e.g. granular events, one-shot notes). Forgetting doneAction:2 leads to server overload: each trigger creates a new node that never dies. Gate-controlled envelopes (Env.asr, Env.adsr) support release via synth.set(\gate, 0), triggering a release phase before freeing.

Examples

SynthDef(\blip, {
  var env = EnvGen.ar(Env.perc(0.01, 0.3), doneAction:2);
  Out.ar(0, SinOsc.ar(440) * env * 0.2)
}).add;
Synth(\blip); // auto-frees after 0.31s

Assessment

Create a percussive SynthDef, spawn 10 copies in a loop, and verify in the server status that node count returns to its starting value after all envelopes complete. Then try the same without doneAction:2 and observe the difference.

“The doneAction argument means that the envelope, on completion, causes its enclosing Synth to be freed.”