v8-memoryAnswer last reviewed July 2026

You've got a container with a 512MB memory limit, and the kernel keeps OOM-killing your Node process. What's actually going on, and how do you fix it properly?

A good answer keeps the V8 heap limit separate from total process memory and sizes both against the cgroup limit with honest headroom

What an AI-prepared candidate might say

That's the kernel OOM killer. It terminates the process when the container's total memory crosses the cgroup limit. With Node the usual cause is that V8's default heap limit doesn't match the container. V8 sizes its heap from the memory it detects, which can be way more than 512MB, so the heap grows past what the container allows and the kernel kills the process before V8 even thinks it's out of memory. The fix is setting --max-old-space-size explicitly, around 400MB for a 512MB container I think, so V8 collects harder and throws a heap-out-of-memory error instead of getting killed. It's also worth checking for a memory leak, because a leak will hit any limit eventually. And setting the flag through NODE_OPTIONS keeps it consistent across entrypoints.

Senior
Locked

Everything RSS holds beyond the JS heap, external buffers, thread stacks, code, allocator slack, plus how to tell the two OOM signatures apart by their exit codes.

Unlock the depth
Staff
Locked

The headroom arithmetic you'd actually run for a real service, the GC thrashing that shows up near the limit, and keeping the flag in lockstep with the cgroup at the entrypoint.

Unlock the depth
Follow-up chain
You've got a container with a 512MB memory limit, and the kernel keeps OOM-killing your Node process. What's actually going on, and how do you fix it properly? | NodeBook