The Trivial Things You Can Learn When Stress Testing an AJAX Application

Friday, January 18, 2008

Internet Explorer has no problem creating an array of 65,536 elements.

var array = [];
for(var i = 0; i < 65535; i++)
{
    array.push(i);
}    
array.push(i);

alert(array.length);
// says 65536

However, IE does have a problem eval-ing an array of 65,536 elements.

var buffer = '[0';
for(var i = 0; i < 65535 / 15; i++)
{
    buffer +=
',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0';
}
buffer +=
']';

var array = eval(buffer);    
alert(array.length);
// would be 65536,
                     // if it got this far..

The code produces an out of memory error on the eval statement. The limit for eval appears to be 65,535 – a number that harkens back to the dark, dismal days of programming in a segmented memory architecture.

Of course, if you came here looking for the upper limits of evalyou might be doing something wrong!


Comments
Josh Stodola Friday, January 18, 2008
Ahhh yes, two to the power of sixteen minus one. Hear about the Excel bug related to this number?

www.lomont.org/.../Excel2007Bug.pdf
scott Friday, January 18, 2008
Wow - when that paper says it will analyze a bug - it isn't kidding!!
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!