Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

<--- Last few GCs --->
31681 ms: Mark-sweep 654.1 (666.5) -> 492.5 (509.8) MB, 267.5 / 0.0 ms [allocation failure] [GC in old space requested].
31839 ms: Mark-sweep 492.5 (509.8) -> 492.2 (506.8) MB, 157.5 / 0.0 ms [allocation failure] [GC in old space requested].
31985 ms: Mark-sweep 492.2 (506.8) -> 492.2 (497.8) MB, 146.2 / 0.0 ms [last resort gc]. 32122 ms: Mark-sweep 492.2 (497.8) -> 492.2 (497.8) MB, 136.8 / 0.0 ms [last resort gc]. <--- JS stacktrace --->

What is it regarding and how to fix it,

Thanks in advance

How big is the data you're trying to decrypt? You need to figure out what is using too much memory in your node.js app and/or, you need to increase the amount of memory you node.js app has available to it. FYI heap snapshots will help you figure out what your memory is being consumed by. jfriend00 Oct 11, 2017 at 14:20

Alllocate more memory to your script by using the following argument to node: --max_old_space_size=x

Example:

node --max_old_space_size=8000 yourscript.js

This will allocate about 8GB to your script. Eventually this is still not sufficient and you should decrypt your SQL in smaller chunks and make use of your physical drive instead of RAM memory.

Hope this helps!

For anyone needing this setting in a container, you can also set NODE_OPTIONS=--max_old_space_size=8000 as an environment variable – Peter Albert May 7, 2020 at 21:29 I have the same problem in the GitLab runner build and set this parameter but it doesn't work! - export NODE_OPTIONS="--max-old-space-size=8192" - npm install --legacy-peer-deps --no-shrinkwrap --update-binary - CI=false npm run-script build:prod – Mohammad Reza Mousavi Jul 19, 2022 at 15:08 NODE_OPTIONS="--max-old-space-size=8192" should be NODE_OPTIONS="--max_old_space_size=8192". Swap the dashes for underscores in the flag key. – Blake Petersen Dec 16, 2022 at 17:31

Proper solution

Something is using too much memory in your node.js app. This is usually bad sign and requires investigation in long term. To find out the exact piece of code, which does this - you may want to check out node.js profiling techniques. Some article about this https://nodejs.org/en/docs/guides/simple-profiling/

Fast solution

In some cases fast workaround is what we want. For such cases, as correctly pointed out by Cryptic Pug - we can increase JS memory allocation limit. There are few options how to do so (based on your needs)

  • pass argument to node directly
    node --max_old_space_size=4096 app.js
    
  • use environment variable
    NODE_OPTIONS=--max_old_space_size=4096
    node app.js
    
  • use .npmrc file. Put following in .npmrc local or global file
    node-options=--max_old_space_size=4096
    and run your script
    
    node app.js
    

    I was caught in the same issue. When I run the project, it was React js Project, I got the same error.

    <--- Last few GCs --->
    JavaScript heap out of memory
    After 2 hours of research and connecting with my peers, I downgrade my node js version from v14.15.4 to v14.15.3. Restart my PC, And then delete my node_modules and yarn.lock file, and reinstall my packages, run my project, and the error is gone.
    Maybe it will help some others facing the same issue.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •