nodejs内存不足 [英] nodejs out of memory
问题描述
我今天遇到了一个奇怪的问题。对于其他人来说,这可能是一个简单的答案,但它让我难过。为什么下面的代码会导致内存错误?
var cur = 167772160;
$时,内存从几兆到几千秒p $ p>
var bcast = 184549375;
var addresses = [];
while(cur< = bcast){
cur + = 1;
addresses.push(cur);
}
地址。长度
地址//当试图打印这个
我得到了这两个错误中的一个......第一个是我在node的解释器中运行这个代码而后者是我通过nodeunit运行它时:
致命错误:CALL_AND_RETRY_2分配失败 - 处理内存不足
致命错误:JS分配失败 - 处理内存不足
解决方案当我尝试访问阵列时会发生这种情况。
但是获得长度不是。> var cur = 167772160;
> var bcast = 184549375;
> var addresses = [];
> while(cur< = bcast){
... cur + = 1;
... addresses.push(cur);
...}
16777216
> addresses.length
16777216
>地址
致命错误:CALL_AND_RETRY_2分配失败 - 处理内存不足
这是另一个SO问题, Node.js(和chrome V8)中的内存限制与内存使用问题有关。
I came across a curious issue today. This may be an easy answer for others, but it has me stumped. Why does the code below cause a memory error?
var cur = 167772160; var bcast = 184549375; var addresses = []; while (cur <= bcast){ cur += 1; addresses.push(cur); } addresses.length addresses // memory goes from a few megs to over a gig in seconds when trying to print this
I get one of these two errors...the first when i run this code in node's interpreter and the latter when i run it through nodeunit:
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
FATAL ERROR: JS Allocation failed - process out of memory
解决方案It happens when I try to access the array. But getting the length does not.
> var cur = 167772160; > var bcast = 184549375; > var addresses = []; > while (cur <= bcast){ ... cur += 1; ... addresses.push(cur); ... } 16777216 > addresses.length 16777216 > addresses FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
Here's another SO question, memory limit in Node.js (and chrome V8) that relates to issue with memory usage.
这篇关于nodejs内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!