Scsynth memory leak?


I was running some stuff for a while and suddenly I got the exception in real time: alloc failed, increase server's memory allocation (e.g. via ServerOptions) error. I was able to narrow down what may be causing it. The same thing happens with this code (below). Also attached is a little log of sorts that shows it (you can see how the log is rendered in the code too if that’s useful for reading). You can see that scsynth memory starts at 195MB and slowly climbs to 207MB before firing off the memory error (the audio file it is playing is 133MB). I’m just letting this code run–no other reason why I would be adding to the memory usage (I think). (41.5 KB)

		var audioBuf =,"/Volumes/Ted's 10TB My Book (June 2020)/SOUND DESIGNS/_EURORACK SOUNDS/201201 eurorackies/audio/01-201201_1505.wav");
		var synth, bus =,2);
		var vec_size = 7;
		var analysis_bus = Bus.control(s,vec_size);
		var analysis_synth, serverBuf = Buffer.alloc(s,vec_size);
		var ds = FluidDataSet(s);
		var counter = 0;
		var n_indices = 300;
		var circle_buf_full = false;
		var write_buf_synth;


		// play sound
		synth = {
			arg rate = 1;
			var sig =,audioBuf,rate,startPos:rrand(0,audioBuf.numFrames-1),loop:1);
			//var sig =;,Mix(sig));
			sig;// * -20.dbamp;


		analysis_synth = {
			var vector =,2)) / 2);,vector);


		write_buf_synth = {
			var vector =,vec_size);{
				arg i;[i],serverBuf,i,1);

			var name = (counter % n_indices).asString;


			counter = counter + 1;

			if(counter >= n_indices,{circle_buf_full = true;});

		~out = File("/Users/ted/Desktop/%_mem_leak_search.txt".format(Date.localtime.stamp),"w");{
			var str;
			p = Pipe("top -l 1 | grep scsynth","r");
			str = Date.localtime.asString;
			str = str + p.getLine + "\n";;

				arg dict;
				"n points in ds: %".format("data").size).postln;



FWIW a graph of scsynth MB over time: x axis is seconds since the code started essentially. The y axis is taken from the terminal output. It is either floored or rounded, I don’t know but you can still see the general rate.

Cheers @tedmoore (and especial thanks for the thorough documentation). I’ll take a look: I don’t do much with the server’s rt memory pool, so hopefully it’ll be simple enough to trace (that said, I don’t think standard leak tracing tools will help with it).

1 Like

Ok, looking at the scsynth I think there’s a bit where I’ve misunderstood whether or not it takes ownership of some memory, so I can see where the problem might be. I’ve compiled with a hopeful fix, and will leave your thing running for a while (looks like it took about 20 min to croak from above?)

FWIW, I don’t think the output of top will help here: that will report the size of scsynth's heap, but the real-time memory pool is all allocated from the free store when the server boots, and can’t grow (hence the error). However, you will see the heap grow over time with calls to malloc from other threads: that doesn’t necessarily point to a memory leak (because freed memory will be returned to the application free store, not necessarily the OS).

If needed, I can track the real-time pool size in the debugger (I think)

Cool. Thanks for the speedy reply!

Yeah it was about a half hour.

Thank you thank you!!

Cool, well I might just leave it running overnight and see if it still breathes in the morning :smiley:

1 Like

So far, so good. Will report back in some hours :sleeping_bed::sleeping_bed::sleeping_bed:

Still running, so I’ll tentatively call that fixed at this end.