我收到此错误:
FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory
但是我正在使用--max-old-space-size=12288
,并且我有16GB的内存
使用process.memoryUsage()
,我可以看到堆只有大约1GB;
而且,错误总是发生在同一行代码上,即types.js:~94
,这是我正在使用的库的一部分。
这使我觉得某个地方存在错误,也许是在传递给函数的参数中,但是我不知道如何发现它。
我应该找什么?
完整错误是:
<--- Last few GCs --->
[28425:0x2739620] 406975 ms: Scavenge 3689.5 (3833.4) -> 3673.7 (3833.9) MB, 4.2 / 0.0 ms (average mu = 0.991, current mu = 0.990) allocation failure
[28425:0x2739620] 407874 ms: Scavenge 3728.8 (3873.4) -> 3713.1 (3873.9) MB, 4.5 / 0.0 ms (average mu = 0.991, current mu = 0.990) allocation failure
[28425:0x2739620] 408785 ms: Scavenge 3768.1 (3913.4) -> 3752.4 (3913.9) MB, 4.5 / 0.0 ms (average mu = 0.991, current mu = 0.990) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x2a42914841bd]
Security context: 0x281401b9e6c9 <JSObject>
1: decode [0x1c8f15ad00a9] [/media/Data/dev/btc-crawler/node_modules/bitcoin-protocol/src/types.js:~94] [pc=0x2a429178f88b](this=0x1c8f15acb299 <Object map = 0x736c200e801>,buffer=0xeeb6cf17c29 <Uint8Array map = 0x3d1fa97d04e9>,offset=4,end=0x25b4eaf822e1 <undefined>)
2: _transform [0x38503cda5d21] [/me...
FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory
1: 0x89c2f0 node::Abort() [node]
2: 0x89c33c [node]
3: 0xa8f05e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xa8f278 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xe7cad2 [node]
6: 0xf88847 v8::internal::HashTable<v8::internal::StringTable, v8::internal::StringTableShape>::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag, v8::internal::MinimumCapacity) [node]
7: 0xf9a3c8 v8::internal::HashTable<v8::internal::StringTable, v8::internal::StringTableShape>::EnsureCapacity(v8::internal::Handle<v8::internal::StringTable>, int, v8::internal::PretenureFlag) [node]
8: 0xf9a58a v8::internal::StringTable::LookupKey(v8::internal::Isolate*, v8::internal::StringTableKey*) [node]
9: 0xfa03f4 v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>) [node]
10: 0xf678aa v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [node]
11: 0x1112512 in the code, v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, bool*) [node]
12: 0x1112849 [node]
13: 0x1114f09 v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [node]
14: 0x2a42914841bd
types.js的第94行是解码函数的入口点,定义如下:
var buffer12 = struct.Buffer(12)
function decode (buffer, offset, end) {
var bvalue = buffer12.decode(buffer, offset, end)
for (var stop = 0; bvalue[stop] !== 0; ++stop);
for (var i = stop; i < bvalue.length; ++i) {
if (bvalue[i] !== 0) throw new Error('Found a non-null byte after the first null byte in a null-padded string')
}
return bvalue.slice(0, stop).toString('ascii')
}
答案 0 :(得分:1)
您有错字!
正确的用法是node --max-old-space-size=4096 somescript.js
在这种情况下4096是4GB,请根据您的情况进行相应调整...
运行node --v8-options
列出所有有效的v8选项,
或检查this list of v8 flags