FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed — JavaScript heap out of memory

Nirbhay Singh
1 min readMar 17, 2023

This error message is commonly encountered when running a Node.js application or a script that uses the V8 engine (which powers JavaScript) on a system with insufficient memory.

The message indicates that the V8 engine has run out of memory (JavaScript heap), and it is unable to allocate more memory to the application or script.

To resolve this issue, you can try the following steps:

  1. Increase the heap memory limit: You can increase the heap memory limit of Node.js by setting the — max-old-space-size flag to a higher value when running the script or application. For example, you can set it to 4096 MB by running:
  2. node --max-old-space-size=4096
  3. node --max-old-space-size=12288 or node --max-old-space-size=16384,
  4. Optimize your code: If your code is allocating a lot of memory, you can try to optimize it to use less memory. You can use tools such as the Node.js memory profiler to identify memory leaks and optimize your code.
  5. Use a stream-based approach: If you are processing large files or data streams, you can consider using a stream-based approach to process the data in smaller chunks, rather than loading the entire data set into memory.
  6. Upgrade your system’s memory: If none of the above solutions work, you can consider upgrading your system’s memory to provide more memory to the application or script.

--

--

Nirbhay Singh

Technophile, DevOps Consultant at Deloitte, talks about DevOps, Cloud, Site Reliability Engineer, Linux and Programming.