Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much data can a javascript global variable hold?

Tags:

ajax

To enable a go back function with an ajax div i have create these simple functions and i was wondering how much data a .js global variable can hold??

    var dataAfterSearch; //global variable which holds our search results

function goBackAfterSearch() {
    /**
    *   function which displays the previous state
    *
    **/
    $.ajaxSetup ({
        cache: false
    });
    //alert("Previous Search" +dataAfterSearch);
    $('#result').html(dataAfterSearch);
     paginateIt();
}
function setDataAfterSearch(data)
{   
    /**
    * function to set the global dataAfterSearch
    *
    **/
    dataAfterSearch = data;
}

kind regards

like image 203
alex Avatar asked Mar 16 '10 18:03

alex


2 Answers

There is no limit, the maximum size is browser/implementation specific.

You can test the limit by executing a script like this:

var str = "";
var sizeCount = 0;
while( true ) {
   str += "a";
   if( ++sizeCount >= 1048576 ) { // Show an alert for every MB
      alert( str.length );
      sizeCount = 0;
   }
}

I get an error in Chrome around 26MB.

like image 170
Ryan Emerle Avatar answered Jan 01 '23 10:01

Ryan Emerle


Ya there is an limit so far i observed, one of the method was returning a data more than 6MB size of data into java script variable but it could not handle such large amount of data in fact it was throwing error (JVM closed abruptly)i tried in mozilla and IE,this is what i observed.

like image 35
kanakamohan Avatar answered Jan 01 '23 10:01

kanakamohan