skip to Main Content

I was running my NextJs project and during development, it broke for an unknown reason and logged this error message:

<--- Last few GCs --->

[8728:000001A567CE5290]  8719226 ms: Mark-sweep (reduce) 1827.7 (1944.2) -> 1827.7 (1897.2) MB, 668.1 / 0.0 ms  (average mu = 0.411, current mu = 0.171) last resort; GC in old space requested

[8728:000001A567CE5290]  8720395 ms: Mark-sweep (reduce) 1827.7 (1897.2) -> 1827.7 (1889.5) MB, 1169.6 / 0.0 ms  (average mu = 0.173, current mu = 0.000) last resort; GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

1: 00007FF72EB507BF node_api_throw_syntax_error+175823

2: 00007FF72EAD5796 DSA_meth_get_flags+59654

3: 00007FF72EAD7480 DSA_meth_get_flags+67056

4: 00007FF72F57DCC4 v8::Isolate::ReportExternalAllocationLimitReached+116

5: 00007FF72F569052 v8::Isolate::Exit+674

6: 00007FF72F3FFB6E v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+4030

7: 00007FF72F40703A v8::internal::Factory::CodeBuilder::AllocateCode+106 

8: 00007FF72F407CF1 v8::internal::Factory::CodeBuilder::BuildInternal+641

9: 00007FF72F407956 v8::internal::Factory::CodeBuilder::Build+22

10: 00007FF72EE59BC7 v8::internal::RegExpMacroAssemblerX64::GetCode+4215  

11: 00007FF72F125AAE v8::internal::RegExpErrorString+9390

12: 00007FF72F10FCF1 v8::PropertyDescriptor::value+6081

13: 00007FF72F11020C v8::internal::RegExp::CompileForTesting+764

14: 00007FF72F1107F8 v8::internal::RegExp::DotPrintForTesting+248

15: 00007FF72F11187B v8::internal::RegExp::ExperimentalOneshotExec+2795   

16: 00007FF72F11138D v8::internal::RegExp::ExperimentalOneshotExec+1533   

17: 00007FF72F110CD8 v8::internal::RegExp::Exec+216

18: 00007FF72F0EEBC2 v8::internal::DeclarationScope::was_lazily_parsed+22994

19: 00007FF72F61B1F1 v8::internal::SetupIsolateDelegate::SetupHeap+558193 

20: 00007FF72F67DE8A v8::internal::SetupIsolateDelegate::SetupHeap+962826 

21: 00007FF6AFBA1BBA

I was trying to run my project on my local machine. But I am curious to know what you think the cause might be.

2

Answers


  1. Not sure what the cause might be, but to fix it try deleting the .next file and run the dev server again ?

    Login or Signup to reply.
  2. I am curious to know what you think the cause might be.

    The title of your question says it already: you’re out of memory. The key part of the error message is:

    FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

    The reason is that you’re holding on to more live objects than the heap can store. The rest of the stack trace gives the specific allocation attempt that failed: it was a compilation of some regexp, but that’s not necessarily where the actual problem lies, it could just have been the proverbial straw that broke the camel’s back.

    Maybe you’re creating and storing unnecessarily many objects? Do you have some very large (and continuously growing) arrays perhaps? Or large tree-like object structures? The retaining path can be rather non-obvious; you can take a heap snapshot and inspect what’s taking so much space in there and see if you can figure out why all those objects are being held alive.

    Maybe you need to work with a large data set, and it’s already stored as efficiently as possible. In that case, you can raise the maximum heap size that Node will allow, with the --max-old-space-size=N command-line flag, where N is the number of megabytes. Since apparently 1800 isn’t enough, try 3000 or 4000 or even more (assuming your machine has enough memory, of course).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search