Fix Node.js Out of Memory (Heap) — JavaScript Heap OOM

Direct answer

Node.js crashes with heap out of memory when the V8 engine exceeds its memory limit. Increase the heap size with --max-old-space-size as a temporary fix, then use heap snapshots via Chrome DevTools to identify and fix the underlying memory leak.

Structured breakdown

Cause

Node.js OOM crashes happen when the V8 heap exceeds its limit. Increase --max-old-space-size temporarily, then profile with heap snapshots to find memory leaks.

Fix

  • Increase heap size temporarily: node --max-old-space-size=4096 app.js
  • Take heap snapshots with --inspect and Chrome DevTools to identify leaks
  • Stream large files/datasets instead of loading them into memory

Outcome

Node.js process runs within memory limits with identified leaks fixed and proper heap sizing configured.

Common causes

  • Memory leak from unreleased event listeners or closures
  • Large dataset loaded entirely into memory
  • Unbounded cache or Map growing without eviction
  • Heap size limit too low for the workload
  • Circular references preventing garbage collection

Fix steps

  1. 1

    Increase heap size temporarily: node --max-old-space-size=4096 app.js

  2. 2

    Take heap snapshots with --inspect and Chrome DevTools to identify leaks

  3. 3

    Stream large files/datasets instead of loading them into memory

  4. 4

    Add size limits and eviction to all in-memory caches

  5. 5

    Check for event listener leaks — use process._getActiveHandles() to audit

Analyze this issue

Paste the issue description, logs, or symptoms into the fix tool to inspect this problem with your own runtime details.

kintify fix

Need more context?

If the standard steps do not resolve the issue, open the fix tool and include the current logs, configuration, and deployment changes.

Open Fix Tool

Frequently asked questions

These examples show the commands, logs, and configuration patterns most often used to verify this issue.

Command examples

  • node --max-old-space-size=4096 app.js
  • node --inspect app.js
  • node -e "console.log(v8.getHeapStatistics())"

Log snippet

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
<--- Last few GCs --->
[1234:0x5678] 120000 ms: Mark-sweep 1495.2 (1520.1) -> 1494.8 (1520.1) MB

Config snippet

// package.json scripts
"scripts": {
  "start": "node --max-old-space-size=4096 server.js",
  "debug": "node --inspect --max-old-space-size=4096 server.js"
}