最大呼叫堆栈大小超过错误
我正在使用直接的Web远程(DWR)JavaScript库文件,并且仅在Safari(桌面和iPad)中遇到
错误
超过最大呼叫堆栈大小。
此错误到底是什么意思,它是否完全停止处理?
另外,Safari
浏览器的任何修复程序(实际上在iPad Safari
上,它说
JS:执行超过超时
我假设是同一呼叫堆栈问题的超时时间)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
这意味着您在代码中的某个地方调用了一个函数,该功能又调用另一个功能,依此类推,直到达到呼叫堆栈限制为止。
这几乎总是因为递归功能,其基本情况无法满足。
堆栈
考虑此代码...
这是几次调用后的堆栈...
查看 请参阅呼叫堆栈成长,直到达到限制:浏览器硬编码的堆栈尺寸或内存耗尽。
为了修复它,请确保您的递归功能具有能够满足的基本案例...
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...
就我而言,我是在发送输入元素而不是它们的值:
而不是:
这将我的铬片冻结到一个点,甚至没有向我显示“ wait/kill”对话框,因为该页面变得无反应...
In my case, I was sending input elements instead of their values:
Instead of:
This froze my Chrome tab to a point it didn't even show me the 'Wait/Kill' dialog for when the page became unresponsive...
如果您两次意外导入/嵌入相同的JavaScript文件,有时可以得到此功能,值得在检查员的资源选项卡中检查。
You can sometimes get this if you accidentally import/embed the same JavaScript file twice, worth checking in your resources tab of the inspector.
代码中某个地方的某个地方有一个递归循环(即最终一次又一次地调用自己的函数,直到堆栈已满)。
其他浏览器要么具有较大的堆栈(因此您会获得超时),要么出于某种原因吞咽错误(也许是一个不好的trycatch)。
发生错误时,请使用调试器检查呼叫堆栈。
There is a recursive loop somewhere in your code (i.e. a function that eventually calls itself again and again until the stack is full).
Other browsers either have bigger stacks (so you get a timeout instead) or they swallow the error for some reason (maybe a badly placed try-catch).
Use the debugger to check the call stack when the error happens.
检测Stackoverflows的问题有时是堆栈跟踪会放松,您将无法看到实际发生的事情。
我发现Chrome的一些更新的调试工具对此很有用。
点击
性能选项卡
,请确保已启用JavaScript Samples
已启用,您将获得类似的东西。很明显,溢出在这里!如果单击
ExtendObject
,您将可以实际看到代码中的确切行号。您还可以看到可能有帮助或红鲱鱼的时间。
如果您实际上找不到问题是在您认为问题所在的地方放置大量
console.log
语句。上面的前一步可以帮助您解决这个问题。在Chrome中,如果您反复输出相同的数据,它将像这样显示问题更清晰的位置显示。在这种情况下,堆栈在最终崩溃之前击中了7152帧:
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:
就我而言,我使用以下内容将大字节数组转换为字符串:
bytes
包含数百万个条目,这太大了,无法放在堆栈上。In my case, I was converting a large byte array into a string using the following:
bytes
contained several million entries, which is too big to fit on the stack.这也可能导致
最大调用堆栈大小超过
错误:在此处相同:
来自 mozilla docs :
所以尝试:
This can also cause a
Maximum call stack size exceeded
error:Same here:
From the Mozilla Docs:
So try:
就我而言,点击事件正在传播子元素。因此,我不得不说以下内容:
在单击事件上:
这是HTML代码:
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:
就我而言,这是我有2个具有相同名称的变量!
In my case, it was that I have 2 variables with the same name!
检查Chrome Dev工具栏控制台中的错误详细信息,这将为您提供呼叫堆栈中的功能,并引导您朝着导致错误的递归。
Check the error details in the Chrome dev toolbar console, this will give you the functions in the call stack, and guide you towards the recursion that's causing the error.
就我而言,我基本上忘记了
Input
的value
。错误
正确
In my case, I basically forget to get the
value
ofinput
.Wrong
Correct
发送输入元素而不是其值很可能像FK一样解决它
Sending input elements instead of their values will most likely resolve it like FK mentioned
如果由于某种原因需要运行无限的过程/递归,则可以在单独的线程中使用网络工作者。
如果要操纵dom元素并重新绘制,请使用动画
http://creativejs.com/resources/requestanimationframe/
If you need a infinite process/recursion running for some reason, you can use a webworker in a seperate thread.
http://www.html5rocks.com/en/tutorials/workers/basics/
if you want to manipulate dom elements and redraw, use animation
http://creativejs.com/resources/requestanimationframe/
这里几乎每个答案都指出,这只能由无限循环引起。事实并非如此,否则您可以通过深度嵌套的呼叫过度运行堆栈(并不是说这是有效的,但这肯定是可能的领域)。如果您可以控制JavaScript VM,则可以调整堆栈尺寸。例如:
node -stack-size = 2000
另请参见:我如何增加node.js中的最大呼叫堆栈大小
Nearly every answer here states that this can only be caused by an infinite loop. That's not true, you could otherwise over-run the stack through deeply nested calls (not to say that's efficient, but it's certainly in the realm of possible). If you have control of your JavaScript VM, you can adjust the stack size. For example:
node --stack-size=2000
See also: How can I increase the maximum call stack size in Node.js
最近,我们在正在研究的管理站点中添加了一个字段-Contact_Type ...容易吧?好吧,如果您称选择“类型”并尝试通过jQuery ajax调用来发送它,则该错误埋在jquery.js中不执行此操作:
问题是那种类型:类型 - 我相信这是我们命名参数“类型” - 具有命名类型的值变量不是问题。我们将其更改为:
相应地解决问题 - 解决问题。
We recently added a field to an admin site we are working on - contact_type... easy right? Well, if you call the select "type" and try to send that through a jquery ajax call it fails with this error buried deep in jquery.js Don't do this:
The problem is that type:type - I believe it is us naming the argument "type" - having a value variable named type isn't the problem. We changed this to:
And rewrote some_function.php accordingly - problem solved.
就我而言,两种jQuery模式彼此堆叠。防止这解决了我的问题。
In my case, two jQuery modals were showing stacked on top of each other. Preventing that solved my problem.
检查您是否具有调用自己的函数。例如
Check if you have a function that calls itself. For example
对我来说,作为打字稿的初学者,这是 _var1 的getter和setter中的问题。
For me as a beginner in TypeScript, it was a problem in the getter and the setter of _var1.
在上面的
数据
函数中,我使用了相同的名称d.loanref = loanref
,但没有创建一个变量loanref
因此递归声明自己。解决方案:声明
LoanRef
变量或更高的内容,请使用与d.loanref
上使用的名称不同的名称。In the
data
function above, I used the same named.loanRef = loanRef
but had not created a variableloanRef
therefore recursively declaring itself.Solution: Declare a
loanRef
variable or better still, use a different name from the one used ond.loanRef
.问题可能是由于递归电话没有任何基本条件以终止。
就像我的情况下一样,如果您看到以下代码,我的API调用方法的名称相同,并且我用来执行API调用操作的方法。
因此,基本上,解决方案是删除此递归调用。
The issue might be because of recursive calls without any base condition for it to terminate.
Like in my case, if you see the below code, I had the same name for the API call method and the method which I used to perform operations post that API call.
So, basically, the solution is to remove this recursive call.
如果在我的计算机上的Chrome 32中通过1个工作减少了以下相同代码的两种调用,例如17905 vs 17904。如果运行,则会产生错误“ rangeerror:最大呼叫堆栈大小超过”。似乎不是硬编码,而是取决于计算机的硬件。看来,如果作为函数调用,则自我强加的限制比作为方法调用的限制高,即当调用作为函数时,该特定代码使用的内存较少。
称为一种方法:
调用为函数:
Both invocations of the identical code below if decreased by 1 work in Chrome 32 on my computer e.g. 17905 vs 17904. If run as is they will produce the error "RangeError: Maximum call stack size exceeded". It appears to be this limit is not hardcoded but dependant on the hardware of your machine. It does appear that if invoked as a function this self-imposed limit is higher than if invoked as a method i.e. this particular code uses less memory when invoked as a function.
Invoked as a method:
Invoked as a function:
我也面临着类似的问题,这是细节
使用下拉徽标上传徽标上传时上传框
CSS.CSS
校正之前,我的代码是:
console中的错误:
我通过删除
onclick =“ $(#filephoto')。 ()“
来自DIV标签。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.我面临同一问题
我通过删除在Ajax两次使用的字段名称来解决它
例如
I was facing same issue
I have resolved it by removing a field name which was used twice on ajax
e.g
在我的情况下,问题是因为我有孩子路线与父母相同的路线:
所以我不得不删除孩子的路线
The issue in my case is because I have children route with same path with the parent :
So I had to remove the line of the children route
当MongoDB数据库的模式和我们创建的模型不匹配时,我在Express/Nodejs应用程序中遇到了此错误。
I got this error in express/nodejs app, when the schema of MongoDB database and the models which we have created don't match.
就我而言,在app.module.ts中,我遇到了此错误,因为我在Imports和entryComponents中声明了组件。
In my case, in app.module.ts, I got this error because I declared the component in imports and entryComponents.
您可以在Crome浏览器中找到递归功能,按Ctrl+Shift+J,然后在源选项卡中找到代码汇编流,您可以在代码中使用Break Point找到。
you can find your recursive function in crome browser,press ctrl+shift+j and then source tab, which gives you code compilation flow and you can find using break point in 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:
我有这个错误,因为我有两个JS功能,同名
I had this error because I had two JS Functions with the same name
如果您正在使用Google Maps,请检查LAT LNG是否被传递到
新的Google.maps.latlng
是一种适当的格式。就我而言,他们被不确定。If you are working with google maps, then check if the lat lng are being passed into
new google.maps.LatLng
are of a proper format. In my case they were being passed as undefined.