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)
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...
Here is the stack after a handful of calls...
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...
The problem with detecting stackoverflows is sometimes the stack trace will unwind and you won't be able to see what's actually going on.
I've found some of Chrome's newer debugging tools useful for this.
Hit the
Performance tab
, make sureJavascript samples
are enabled and you'll get something like this.It's pretty obvious where the overflow is here! If you click on
extendObject
you'll be able to actually see the exact line number in the code.You can also see timings which may or may not be helpful or a red herring.
Another useful trick if you can't actually find the problem is to put lots of
console.log
statements where you think the problem is. The previous step above can help you with this.In Chrome if you repeatedly output identical data it will display it like this showing where the problem is more clearly. In this instance the stack hit 7152 frames before it finally crashed:
In my case, click event was propagating on child element. So, I had to put the following:
on click event:
Here is the html code:
I know this thread is old, but i think it's worth mentioning the scenario i found this problem so it can help others.
Suppose you have nested elements like this:
You cannot manipulate the child element events inside the event of its parent because it propagates to itself, making recursive calls until the exception is throwed.
So this code will fail:
You have two options to avoid this:
I also faced similar issue here is the details when uploading logo using dropdown logo upload box
CSS.css
before correction my code was :
The error in console:
I solved it by removing
onclick="$('#filePhoto').click()"
from div tag.I was trying to assign a variable, a value, when that variable had not been declared.
Declaring the variable fixed my error.