最大调用堆栈大小超过错误 [英] Maximum call stack size exceeded error

查看:512
本文介绍了最大调用堆栈大小超过错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Direct Web Remoting(DWR)JavaScript库文件,并且仅在Safari(台式机和iPad)中出现错误。




超出最大调用堆栈大小。


这个错误是否意味着它会完全停止处理?



还有对 Safari 浏览器的任何修正(其实在 iPad Safari ,它说


JS:执行超时超时


我假设它是相同的调用堆栈问题)

解决方案

<这意味着你的代码中的某个地方,你正在调用一个函数,然后调用另一个函数等等,直到你达到调用栈的限制。



这是几乎总是因为递归函数的基本情况没有得到满足。



查看堆栈



考虑这个代码...

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

这是几个电话后的堆栈...





你可以看到,调用堆栈增长,直到它达到一个限制:浏览器硬编码堆栈大小或内存耗尽。



为了解决这个问题,确保递归函数具有一个可以满足的基本情况...

 (function a(x){
// The以下条件
//是基本情况
if(!x){
return;
}
a( - x);
}) (10);


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...

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

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...

(function a(x) {
    // The following condition 
    // is the base case.
    if ( ! x) {
        return;
    }
    a(--x);
})(10);

这篇关于最大调用堆栈大小超过错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆