CodePark/ questions / Performance & memory leaks
START PRACTICINGPRACTICE
Backend question · Node.js › Performance & memory leaks

A batch job crashes with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory. The machine has plenty of free RAM. What does the flag --max-old-space-size=4096 do?

Raises V8's old-generation heap limit to about 4 GB

The flag raises V8's old-generation heap limit, in megabytes, so 4096 means about 4 GB. V8 limits the JavaScript heap no matter how much free RAM the machine has. That is why the job crashes even though the machine has plenty of memory.

This is a valid fix when the job really needs more memory. But if memory use keeps growing, you have a leak, and the flag only delays the crash. Often the real fix is to process the data as a stream, piece by piece.


"Sets the maximum size of the call stack" is wrong: the call stack size uses a different flag,
--stack-size. The flag has nothing to do with the libuv thread pool or with allocating Buffer memory up front.