Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start by identifying the process that failed. For a Node.js program or frontend build, check the machine or container’s memory budget, then run the process with a supportable --max-old-space-size value. For a browser tab, use Chrome DevTools’ Memory panel instead; a Node.js flag cannot repair a leak in an unrelated page. If memory keeps growing after a larger limit, profile retained objects rather than raising the limit again.

What “JavaScript heap out of memory” means

Node.js runs JavaScript on V8, which stores objects in a managed heap. Messages such as Reached heap limit or Allocation failed - JavaScript heap out of memory mean V8 could not satisfy an allocation near its configured old-space limit. Garbage collection may run repeatedly as the limit approaches, but collection cannot free objects that are still reachable.

The error names a runtime, not a single root cause. A legitimate build can need more memory than its default ceiling, while a leak can cause a process to grow without bound. First determine whether the failing process is Node.js (including webpack and other build tools) or a browser page.

Choose the remedy by runtime and symptom

Where it fails Typical pattern First action Long-term investigation
Node.js script, test runner or server Process stops near a repeatable heap size Set a heap limit that the host can actually provide Heap snapshots and retaining-reference analysis
Webpack or another Node-based build Large compilation or asset optimization exhausts memory Pass NODE_OPTIONS to the build process Profile plugins, loaders and generated data if growth persists
Browser tab Page slows or crashes after repeated interaction Chrome DevTools Memory panel and heap snapshots Compare snapshots; inspect detached DOM nodes and retaining paths

Fix a Node.js process safely

1. Measure the host’s real budget

Check physical memory, container limits and memory already used by the operating system and other services. The V8 heap is only one part of a process: native allocations, buffers, threads and child processes also consume memory. A limit larger than the available budget can trigger swapping, an operating-system kill or a container out-of-memory termination.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Node’s command-line documentation gives a concrete example: on a 2 GiB machine, consider 1536 MiB for old space so other uses have room and swapping is less likely. That is an example for that machine size, not a universal recommendation.

2. Set --max-old-space-size

The value is expressed in mebibytes (MiB) and sets the maximum size of V8’s old-memory section. Run the flag before your entry file:

node --max-old-space-size=1536 index.js

Replace 1536 with a value your environment can sustain. In CI or a container, use the memory limit assigned to that job, leaving headroom for the runtime and tools. Do not copy a 4096 MiB command onto a 2 GiB host.

3. Make the setting repeatable

For a package script, put the option in the command that launches Node, or set NODE_OPTIONS in the environment used by the script. Keep the value visible in your CI configuration so local and pipeline behavior can be compared.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
NODE_OPTIONS="--max-old-space-size=1536" node index.js

On Windows PowerShell, the equivalent environment assignment is:

$env:NODE_OPTIONS="--max-old-space-size=1536"; node index.js

Verify that the flag reaches the process that actually fails. A wrapper may start a child Node process with different options, and setting a variable in one shell does not change an already-running process.

Rank #2
Programming Code Console Log Javascript Debugging Programmer Hardcover Journal, Black
  • Programming Code Console Log Javascript Debugging T-shirt. Funny Console Log design perfect for computer geeks, frontend developers, programmers, IT specialist, or engineers. Perfect for men women or anyone who love code and programming as a gift birthda.
  • Great gift idea for anybody who works with or as an IT professionals, computer scientists, developers, programmers, software engineers, coders, and anyone with an interest in Javascript, HTML, and any other languages. Wear it to the office or anywhere!
  • Hardcover journal with 240 line-ruled pages (120 sheets)
  • Built-in elastic closure and ribbon bookmark
  • Includes an expandable inner storage pocket and a pen holder

Webpack and frontend build failures

Webpack documents this form for increasing the Node process limit:

NODE_OPTIONS="--max-old-space-size=4096" webpack

Select a number based on the build runner’s memory budget, not the example’s 4096 MiB. If your package script invokes webpack indirectly, place NODE_OPTIONS before the package-manager command so the spawned process inherits it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
NODE_OPTIONS="--max-old-space-size=1536" npm run build

For a one-off diagnosis, run the same build once with the larger, supportable value and record peak memory. If it succeeds and memory returns to a stable level between builds, the original ceiling may simply have been too low. If each build consumes more memory than the previous one, or the process still approaches the new ceiling, treat that as evidence for retained data or an unusually large workload.

When raising the limit is not enough

Recognize a bounded peak

A bounded workload has a predictable high-water mark: memory rises during parsing or compilation, then falls or levels off after the work completes. Increasing the ceiling can be reasonable when the host has unused capacity and the workload is known to be large.

Recognize sustained growth

Growth that continues across requests, test suites, rebuilds or repeated UI actions indicates objects remain reachable. A higher ceiling only postpones failure and may make the eventual crash more disruptive. Investigate allocations and ownership instead of repeatedly increasing the number.

Capture and compare Node.js heap snapshots

Node.js supports taking heap snapshots near the heap limit, and its learning guidance describes taking snapshots from a running application and opening them in Chrome DevTools. Snapshot creation pauses the main thread and can require substantial additional memory, so avoid doing it casually on a production process whose availability matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Reproduce the same workload or request sequence under comparable conditions.
  2. Capture a snapshot before the suspected growth and another after it.
  3. Open both snapshots in Chrome DevTools and compare object counts and retained sizes.
  4. For objects that should have expired, inspect retaining paths to find the collection, cache, listener or closure that still references them.
  5. Repeat after a code change to confirm that the retained set no longer grows.

Compare snapshots at equivalent points. A snapshot taken during a large, expected compilation phase is not directly comparable with an idle snapshot. Also account for caches that are intentionally bounded and for temporary allocations that disappear after garbage collection.

Diagnose a browser-tab memory problem

A browser page has its own JavaScript objects and DOM tree. If the tab is the failing runtime, launch Chrome DevTools, open the Memory panel, choose Heap snapshot, and record a snapshot. Reproduce the interaction that causes growth, take another snapshot at the same logical point, and compare them.

Inspect retaining paths

Snapshots show reachable objects. Select a growing object or class and follow its retaining path to the object that keeps it alive. Common causes include application-wide arrays, caches without eviction, event listeners that are never removed and closures holding large data.

Check for detached DOM nodes

A node removed from the document can remain alive when JavaScript still references it. In the snapshot, look for detached elements and inspect the retaining path. Remove the stale reference only when the application no longer needs it; do not delete a reference that is still required for active UI state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshooting common failures

The flag appears to do nothing

  • Wrong process: The error may come from a child process, webpack worker or a different command. Put the option on the command that launches that process.
  • Unsupported placement: Node options must precede the script path, as in node --max-old-space-size=1536 index.js.
  • Environment not inherited: Confirm that your CI step, shell and package script pass NODE_OPTIONS to the failing process.

The container is killed after increasing memory

The new heap ceiling may exceed the container or job limit, or leave too little memory for native allocations and other processes. Lower the value, raise the container’s memory allocation if you control it, or reduce workload parallelism. A JavaScript heap setting cannot override a host-level limit.

The build succeeds once, then fails later

Check whether the workload differs, caches accumulate between runs or a plugin retains state. Run comparable builds, capture snapshots around the point of growth and inspect retained objects. Do not conclude that a one-time success proves a leak was fixed.

Rank #4
Programming Code Console Log Javascript Debugging Programmer Hardcover Journal, Black
  • Programming Code Console Log Javascript Debugging T-shirt. Funny Console Log design perfect for computer geeks, frontend developers, programmers, IT specialist, or engineers. Perfect for men women or anyone who love code and programming as a gift birthda.
  • Great gift idea for anybody who works with or as an IT professionals, computer scientists, developers, programmers, software engineers, coders, and anyone with an interest in Javascript, HTML, and any other languages. Wear it to the office or anywhere!
  • Hardcover journal with 240 line-ruled pages (120 sheets)
  • Built-in elastic closure and ribbon bookmark
  • Includes an expandable inner storage pocket and a pen holder

A browser snapshot is too large or freezes the tab

Snapshot generation pauses execution and may need substantial memory. Reproduce with a smaller dataset, close unrelated tabs, capture during a controlled test session and avoid taking snapshots on a production page used by customers.

Only one route or interaction leaks

Record a baseline snapshot, perform that route repeatedly, then compare snapshots. Follow retaining paths from detached nodes, listeners and collections created by that route. The relevant fix is lifecycle cleanup, not a Node.js command-line flag.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Performance, reliability and cost considerations

  • Leave headroom: Node’s 1536 MiB example on a 2 GiB machine illustrates why the heap cannot consume all available memory.
  • Expect longer garbage-collection work: A larger heap can permit more live data but may also make collection pauses more expensive.
  • Profile representative workloads: Measure the same input size, concurrency and build settings when comparing limits.
  • Protect production availability: Heap snapshots pause the main thread and consume memory; use a replica or maintenance window when possible.
  • Prefer bounded data structures: Set cache sizes, remove listeners during teardown and release references when a request or component ends.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need screenshots of a page while documenting or monitoring a failure, ScreenshotNeo provides a website screenshot API and MCP server. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers identify the page verdict and billing result. Its MCP tools—take_screenshot, get_page_info and capture_pdf—work with Claude, Cursor and other MCP clients.

One request returns PNG, JPEG, WebP or PDF. The API also supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets or custom viewports, retina scale, PDF paper and page controls, custom CSS and JavaScript, clicks, selector or network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen TTL caching, signed links, asynchronous signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Parameter names used by other screenshot APIs also work, easing migration.

Use the ScreenshotNeo documentation for the complete option list. A minimal cURL call is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The Free plan includes 1,000 screenshots each month without a card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

FAQ

Does this error always mean a memory leak?

No. It can be a legitimate workload peak that exceeds the configured ceiling, or sustained retention of objects. The runtime and growth pattern determine the next step.

Is the value for --max-old-space-size measured in bytes?

No. Node’s option uses MiB for the V8 old-space limit.

Can I fix a browser memory leak with NODE_OPTIONS?

No. That variable affects Node.js processes. Use Chrome DevTools Memory snapshots for a browser page.

Why can a larger heap make an outage worse?

It permits the process to consume more host memory, potentially causing swapping or a host/container termination instead of an earlier, clearer failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does this error always mean a memory leak?

No. It can be a legitimate workload peak that exceeds the configured ceiling, or sustained retention of objects. The runtime and growth pattern determine the next step.

Is the value for –max-old-space-size measured in bytes?

No. Node’s option uses MiB for the V8 old-space limit.

Can I fix a browser memory leak with NODE_OPTIONS?

No. That variable affects Node.js processes. Use Chrome DevTools Memory snapshots for a browser page.

Why can a larger heap make an outage worse?

It permits the process to consume more host memory, potentially causing swapping or a host/container termination instead of an earlier, clearer failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Bottom Line

Use a supportable Node.js heap limit for a bounded workload; use heap snapshots and retaining-path analysis when memory keeps growing. Browser leaks require Chrome DevTools, not a Node.js flag.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.