Docs for Sampler Need to Mention GC

I really love this new thorough addition to the official docs:

But, there’s no mention of explicitly clearing the buffers used for initially configuring the sampler. If the buffers aren’t explicitly cleared, a big chunk of memory won’t ever be garbage collected. I don’t see this important “gotcha” documented anywhere, it would be really helpful for those running into the memory ceiling:


class Recorder {

buffers = null;

function start() {
    buffers = [blob(this.buffersize), blob(this.buffersize), blob(this.buffersize)];

    hardware.sampler.configure(mic, this.sampleRate, buffers, samplesReady.bindenv(this), this.sampleOptions);


function stop() {
    hardware.sampler.stop();    // buffers are not cleared here, so we must do so explicitly

    // now we have our huge chunk of memory back


The lala board example code reconfigures the buffers with tiny blobs as a hack to clear out the memory:

Ideally, I think the buffers should be cleared on hardware.sampler.stop().

Like everything else in Squirrel, the buffers are kept until no references to them remain. In the code above, the Recorder class itself holds references to them until you call buffers.clear(). To clear the sampler’s own references to those buffers, use sampler.reset(). I’m not sure why the Lala code doesn’t use sampler.reset() – perhaps it was written before that call’s introduction, in release 27.



Thanks for directing me to sampler.reset. Why is this functionality not paralleled with the fixedfrequencydac? It seems the fixedfrequencydac releases memory on it’s own, without any explicit clearing.

Thank you.