Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory

Error:

<--- 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...

I am getting this error every time I run my app.js file and click on a page, it tries to load for a minute without success and then crash. I know this question been asked before.

However, I have tried:

export NODE_OPTIONS=--max_old_space_size=4096

I also tried:

node --max_old_space_size=4096 app.js

and then run my app.js and problem still the same. I am not sure where my exported variables go, cannot find the .bashrc file anywhere etc. I am not even sure what's wrong, I am a bit new into coding.

like image 996
Gabriel Nessi Avatar asked May 27 '19 18:05

Gabriel Nessi


People also ask

How do I stop JavaScript Heap out of memory?

Open the Start menu, search for Advanced System Settings, and select the Best match. In the Variable name field enter NODE_OPTIONS. In the Variable value field enter --max-old-space-size=4096. This value will allocate 4GB of virtual memory to Node.

What does invalid array length mean?

The JavaScript exception "Invalid array length" occurs when specifying an array length that is either negative, a floating number or exceeds the maximum supported by the platform (i.e. when creating an Array or ArrayBuffer , or when setting the length property).


1 Answers

ANSWER:

I managed to solve it, I had an infinite loop working in the background as @alfasin suggested.

like image 172
Gabriel Nessi Avatar answered Oct 01 '22 15:10

Gabriel Nessi