Maximum call stack size exceeded error

后端 未结 30 2973
独厮守ぢ
独厮守ぢ 2020-11-21 23:51

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

30条回答
  •  萌比男神i
    2020-11-22 00:33

    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);
    

提交回复
热议问题