且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Javascript中堆栈与堆? (超出最大调用堆栈大小)

更新时间:2023-10-29 23:18:16

这里有在Javascript中没有将内存分离到堆栈/堆中。你看到的可能是以下之一:

There's no separation of memory into stack/heap in Javascript. What you seeing could be one of following:


  1. 递归太深了。在这种情况下,您需要检查您的算法以使其更加迭代并使用更少的递归,这样您就不会达到浏览器强加的调用堆栈限制。

  2. 如果你的算法没有深度递归,考虑到你的代码是生成的,这可能仍然只是一个足够深的调用。

  3. 最后,一些引擎可能会分配函数参数和范围命名变量在某种内部堆栈上进行快速查找。如果您(或自动生成的代码)恰好在函数中使用了数千个局部变量或参数,这也可能会溢出特定于引擎的限制。

  1. Recursion that ran too deep. In that case you'll need to review your algorithm to make it more iterative and use less recursion so you don't hit call stack limits imposed by browsers.
  2. If your algorithm do not have deep recursion, this might still be just a deep enough call, considering that your code is generated.
  3. Lastly, some engines may allocate function arguments and scoped named variables on some sort of internal stack for fast lookup. If you (or automatically generated code) happens to literally use thousands of local variables or arguments in function, this may overflow engine-specific limits as well.