Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how much data can javascript in the browser hold?

I have created a JSFiddle to see how much data I can push into my browser.

The link is http://jsfiddle.net/GWxAk/

The code is simple. It's just trying to push as many strings as possible into an array. The strings have an approximate length of 300-310 characters.

My question is: does the result depend on how much memory I have got on my PC ? does it really differ browser to browser ?

For instance if I have 8gb of ram will I get much more then if I have 4gb ?

var s = '';
for (var i = 0; i < 300; i++) {
    s += 'a';
}

array = [];
count = 0;

function doMore() {
    for (var i = 0; i < 1000; i++) {
        count++;
        array.push(s + count);
    }
};

function repeat() {
    doMore();
    document.body.innerHTML = 'size:' + array.length;
    setTimeout(repeat, 100);
}

repeat();

In my case chrome hangs at 14850000 and I have 4gb of ram That is an array of almost 15 million items. Not bad I guess

Do you guys get the same ? Can somebody tell how to give as much memory as possible to the browser

Thanks

like image 422
Zo72 Avatar asked Nov 09 '11 15:11

Zo72


2 Answers

I am ON Chrome and i tried your test and it hangs on the same 14850000 you mentioned even if i only have 2gb of ram and i am running a VM with windows inside my linux installation that i gave 700Mb of ram so i guess yes chrome has a limit

like image 132
Qchmqs Avatar answered Sep 23 '22 09:09

Qchmqs


Again, my machine with 16GB of RAM. I can watch the browser RAM usage climb as it increases, so I would assume it's limited by RAM as well.

IE crapped out at 16,840,000
Chrome at 14,850,000
Firefox 32,890,000
Safari recycles itself around 8,720,000 (LOL @ Apple)

Here is a screenshot of memory usage and firefox http://screencast.com/t/3Xl31yGgHWC

like image 32
Anthony Shaw Avatar answered Sep 26 '22 09:09

Anthony Shaw