Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum call stack size exceeded error

I am using a Direct Web Remoting (DWR) JavaScript library file and am getting an error only in Safari (desktop and iPad)

It says

Maximum call stack size exceeded.

What exactly does this error mean and does it stop processing completely?

Also any fix for Safari browser (Actually on the iPad Safari, it says

JS:execution exceeded timeout

which I am assuming is the same call stack issue)

like image 978
copenndthagen Avatar asked May 23 '11 09:05

copenndthagen


People also ask

How do I fix maximum call stack size exceeded error?

The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created.

How do I fix maximum call stack size exceeded NPM?

If you don't want to run npm install every time you change the NodeJS version, then I recommend you to use Node Version Manager to install multiple NodeJS versions on your local computer. You should be able to install all dependencies without the maximum call stack size exceeded error now.

Which of the given code snippet leads to maximum call stack size exceeded error?

Introduction. If you see the “Maximum Call Stack Size Exceeded” error, there's likely a problem with a recursive function within your JavaScript code. More specifically, the issue lies with the function calling on itself indefinitely.

How do I fix maximum call stack size exceeded see JavaScript console for details?

The "RangeError: Maximum call stack size exceeded" error occurs when a function is called so many times that the invocations exceed the call stack limit. To solve the error, specify a base case that has to be met to exit the recursion.


2 Answers

It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.

This is almost always because of a recursive function with a base case that isn't being met.

Viewing the stack

Consider this code...

(function a() {     a(); })(); 

Here is the stack after a handful of calls...

Web Inspector

As you can see, the call stack grows until it hits a limit: the browser hardcoded stack size or memory exhaustion.

In order to fix it, ensure that your recursive function has a base case which is able to be met...

(function a(x) {     // The following condition      // is the base case.     if ( ! x) {         return;     }     a(--x); })(10); 
like image 133
alex Avatar answered Sep 23 '22 23:09

alex


You can sometimes get this if you accidentally import/embed the same JavaScript file twice, worth checking in your resources tab of the inspector.

like image 41
lucygenik Avatar answered Sep 26 '22 23:09

lucygenik