Question

Here is a recursive function for endless loop.

<html>
<body>
<script type="text/javascript">

function repeat(x){
document.write(x+" ");
repeat(x+1);
}

repeat(1);

</script>
</body>
</html>

Using the function, I can see how many recursive calls took place there before out of memory. First time, I run it on firefox.

Result -> 1 2 3 .... upto 40536

Now, I refresh the page

Result -> 1 2 3 ... upto 46046

!! Again refreshing or running on different browsers, I got different results.

How can this be possible? What is the call stack logic/limit for recursion in javascript?

Était-ce utile?

La solution

Internet Explorer 7: 1,789
Firefox 3: 3,000
Chrome 1: 21,837
Opera 9.62: 10,000
Safari 3.2: 500

This are all the some of limits

refer this http://javascriptrules.com/2009/06/30/limitation-on-call-stacks/

and also this

http://www.nczonline.net/blog/2009/05/19/javascript-stack-overflow-error/

Autres conseils

The JavaScript specification does not mandate any particular memory limit. Each implementation can impose whatever memory limit it wants.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top