javascriptnode.jswindows

App claims out of memory despite enough allocated


I am running Windows 11 64bit with 32GB of RAM. No other processes are running. I init Node.js using this command

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

In task manager I see 50% memory usage. So why does the app crash at 4GB?

<--- Last few GCs --->
[11724:000001EAD7670000]  9250018 ms: Mark-Compact 4044.3 (4144.3) -> 4043.1 (4143.9) MB, pooled: 0 MB, 2449.39 / 0.00 ms  (average mu = 0.398, current mu = 0.204) allocation failure; scavenge might not succeed
[11724:000001EAD7670000]  9252815 ms: Mark-Compact 4044.5 (4144.3) -> 4043.7 (4144.6) MB, pooled: 0 MB, 2216.51 / 0.00 ms  (average mu = 0.314, current mu = 0.207) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Solution

  • You're passing the --max-old-space-size argument to the script, not to Node itself.

    Switch the arguments around:

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