Sizing5 min read
Why your Node app dies at 2 GB on a 4 GB plan
The container limit and the V8 heap limit are two different ceilings. Your process hits the lower one first.
A Node process on a 4 GB plan that dies while the panel graph shows 2 GB free is not a hosting bug. Node has its own heap ceiling, set independently of how much memory the container has, and by default it is well below the plan.
Two ceilings
The container limit is what we give the server. The V8 heap limit is what Node allows its own JavaScript objects to occupy before it gives up and throws. Older Node versions default the heap to around 1.5-2 GB regardless of the machine; newer ones read the container but not always correctly.
Raising it
node --max-old-space-size=3072 server.jsSet it a few hundred megabytes below the plan, never at it. The heap is not the whole process - buffers, native modules and the runtime itself live outside it, and a heap set to exactly the container size means the kernel stops the process before V8 ever gets to run a garbage collection.
But check that you need it first
An app that grows until it hits any ceiling has a leak, and raising the ceiling buys hours rather than fixing it. If memory climbs steadily under constant load, the number to change is in your code and not in the start command.