mr_urf
mr_urf

Reputation: 3353

Is there a limit to the number of JavaScript objects you can have on the go at any one time?

I'm looking into converting a Flash application I have into JavaScript but was told that it probably wouldn't be possible due to the number of objects I would have to have on the go.

Is this is true and, if it is, what are the limits?

Upvotes: 1

Views: 824

Answers (3)

AnthonyWJones
AnthonyWJones

Reputation: 189535

Flash is very efficient at moving objects around since that's its primary function. Using JavaScript to move objects around in HTML is going to way, way slower. Nevertheless quite amazing things can be acheived with JavaScript.

See Lemmings.

Upvotes: 3

Per Stilling
Per Stilling

Reputation: 876

JavaScript memory limit shows that you can allocate at least 20 MB of memory in Firefox.

There is definitely a limit though, but I doubt you'll meet the limit on memory. It is more likely that your performance will be too bad if you are converting a very dynamic Flash application.

Upvotes: 3

some
some

Reputation: 49632

An improved version of the script at link text. This is faster since it uses join, and lets the browser have some time to update the page evey now and then.

function allocate_mem() {
    var mega=[];
    // Strings are stored as UTF-16 = 2 bytes per character.
    // Below a 1Mibi byte string is created
    for(var i=0; i<65536; i++){
        mega.push('12345678')
    }
    mega=mega.join("");

    var x=document.getElementById("max_mem");

    var size=0;
    var large=[];
    function allocate( ) {
        ++size;
        //if (size>400) {alert(large.join("").length/1048576); return; }
        large.push("."+mega.slice(0));
            x.innerHTML = "max memory = " + size + " MB";
        setTimeout(allocate, size %10 ? 0: 200);
    }

    allocate();

}

Upvotes: 1

Related Questions