user3696992
user3696992

Reputation: 11

ScriptProcessorNode Memory leak

I'm working on a large project that relies heavily on web audio and ScriptProcessorNodes. After some recent intermittent crashing I've tracked down the problems to memory leaking from the ScriptProcessorNodes. I've read many many tutorials, guides, bug reports, etc.. and none of it seems to be helping. Here's a small toy example:

http://jsfiddle.net/6YBWf/

var context = new webkitAudioContext();

function killNode(node)
{
    return function()
    {
        node.disconnect();
        node.onaudioprocess = null;
        node = null;
    }
}

function noise() 
{
    var node = context.createScriptProcessor(1024, 0, 1);
    node.onaudioprocess = function(e)
    {
        var output = e.outputBuffer.getChannelData(0);
        for(var i = 0; i < 1024; ++i)
        {
            output[i] = (Math.random() * 2 - 1) * 0.001;
        }
    }

    node.connect(context.destination);
    setTimeout(killNode(node), 100);
}


function generateNoise()
{
    for(var i = 0; i < 99999; ++i)
    {
        noise();   
    }
}

generateNoise();

This will spin up many nodes and then disconnect them and set their onaudioprocess to null. From what I've read, given that I'm not retaining any references to them, shouldn't they get garbage collected?

My computer memory jumps up to about 16% and settles down to 14% a bit later but never goes below that. Can anyone show me an example similar to this where the nodes get properly collected? Is there something obvious I'm missing?

Upvotes: 0

Views: 296

Answers (1)

user3696992
user3696992

Reputation: 11

This has been confirmed as a regression in Chrome:

https://code.google.com/p/chromium/issues/detail?id=379753

Upvotes: 1

Related Questions