严重错误:无效的数组长度分配失败-JavaScript堆内存不足

时间:2019-05-27 18:05:34

标签: javascript node.js

错误:

<--- Last few GCs --->

[873:0x1020aa000]    47109 ms: Scavenge 2107.9 (2131.9) -> 2092.1 (2131.9) MB, 0.3 / 0.0 ms  (average mu = 0.995, current mu = 0.999) allocation failure 
[873:0x1020aa000]    47231 ms: Scavenge 2107.9 (2131.9) -> 2092.1 (2131.9) MB, 0.2 / 0.0 ms  (average mu = 0.995, current mu = 0.999) allocation failure 
[873:0x1020aa000]    47353 ms: Scavenge 2107.9 (2131.9) -> 2092.1 (2131.9) MB, 0.2 / 0.0 ms  (average mu = 0.995, current mu = 0.999) allocation failure 


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x27af028cfc7d]
Security context: 0x00a9d921d971 <JSObject>
    1: push [0xa9d9205831](this=0x00a92dc86431 <JSArray[112813858]>,0x00a9f2d5fdf1 <String[17]\: \n                >)
    2: /* anonymous */ [0xa92dc86471] [0x00a9bba025b1 <undefined>:~1] [pc=0x27af02959ff7](this=0x00a9051847e1 <JSGlobal Object>,0x00a92dc86531 <Object map = 0xa982312831>,0x00a9f2d4f6a9 <JSFunction exports.escapeXML (sfi = 0xa9f2d4edc9)>,0x00...

FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
 1: 0x100060e87 node::Abort() [/usr/local/Cellar/node/11.10.1/bin/node]
 2: 0x1000614f5 node::OnFatalError(char const*, char const*) [/usr/local/Cellar/node/11.10.1/bin/node]
 3: 0x10017a687 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/11.10.1/bin/node]
 4: 0x10017a628 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/Cellar/node/11.10.1/bin/node]
 5: 0x100437638 v8::internal::Heap::UpdateSurvivalStatistics(int) [/usr/local/Cellar/node/11.10.1/bin/node]
 6: 0x10041de6a v8::internal::Factory::AllocateRawFixedArray(int, v8::internal::PretenureFlag) [/usr/local/Cellar/node/11.10.1/bin/node]
 7: 0x10041d781 v8::internal::Factory::NewFixedArrayWithFiller(v8::internal::Heap::RootListIndex, int, v8::internal::Object*, v8::internal::PretenureFlag) [/usr/local/Cellar/node/11.10.1/bin/node]
 8: 0x1003dce56 v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::ConvertElementsWithCapacity(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::FixedArrayBase>, v8::internal::ElementsKind, unsigned int, unsigned int, unsigned int, int) [/usr/local/Cellar/node/11.10.1/bin/node]
 9: 0x1003dcd0c v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacityAndConvertImpl(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/usr/local/Cellar/node/11.10.1/bin/node]
10: 0x1003db82a v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::Add(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, unsigned int) [/usr/local/Cellar/node/11.10.1/bin/node]
11: 0x1005068dc v8::internal::JSObject::AddDataElement(v8::internal::Handle<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes) [/usr/local/Cellar/node/11.10.1/bin/node]
12: 0x100505a38 v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes, v8::internal::ShouldThrow, v8::internal::Object::StoreFromKeyed) [/usr/local/Cellar/node/11.10.1/bin/node]
13: 0x10060fd43 v8::internal::Runtime::SetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::LanguageMode) [/usr/local/Cellar/node/11.10.1/bin/node]
14: 0x100612c8c v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node/11.10.1/bin/node]
15: 0x27af028cfc7d 
[nodemon] app crashed - waiting for file changes before starting...

每次运行app.js文件并单击页面时,都会出现此错误,它尝试加载一分钟而没有成功,然后崩溃。我知道以前曾问过这个问题。

但是,我已经尝试过:

export NODE_OPTIONS=--max_old_space_size=4096

我也尝试过:

node --max_old_space_size=4096 app.js

,然后运行我的app.js,问题仍然相同。我不确定导出的变量在哪里,无法在任何地方找到.bashrc文件,等等。我什至不知道出了什么问题,我对编码有点陌生。

1 个答案:

答案 0 :(得分:1)

答案:

我设法解决了这个问题,正如@alfasin建议的那样,我在后台运行了一个无限循环。