memory limit in Node.js (and chrome V8)

Memory Managementnode.js

Memory Management Problem Overview


In many places in the web, you will see:

> What is the memory limit on a node process?

and the answer:

> Currently, by default V8 has a memory limit of 512mb on 32-bit systems, and 1gb on 64-bit systems. The limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit), but it is recommended that you split your single process into several workers if you are hitting memory limits.

Can somebody confirm this is the case as Node.js seems to update frequently?

And more importantly, will it be the case in the near future?

I want to write JavaScript code which might have to deal with 4gb of javascript objects (and speed might not be an issue).

If I can't do it in Node, I will end up doing in java (on a 64bit machine) but I would rather not.

Memory Management Solutions


Solution 1 - Memory Management

This has been a big concern for some using Node.js, and there are good news. The new memory limit for V8 is now unknown (not tested) for 64bit and raised to as much as 32bit address space allows in 32bit environments.

Read more here: http://code.google.com/p/v8/issues/detail?id=847

Solution 2 - Memory Management

Starting nodejs app with a heap memory of 8 GB

node --max-old-space-size=8192 app.js

See node command line options documentation or run:

node --help --v8-options

Solution 3 - Memory Management

I'm running a proc now on Ubuntu linux that has a definite memory leak and node 0.6.0 is pushing 8gb. Think it's handled :).

Solution 4 - Memory Management

It looks like it's true. When I had tried to allocate 50 Mb string in buffer:

var buf = new Buffer(50*1024*1024);

I've got an error:

FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory

Meantime there was about 457 Mb of memory usage by Node.js in process monitor.

Solution 5 - Memory Management

Memory Limit Max Value is 3049 for 32bit users

If you are running Node.js with os.arch() === 'ia32' is true, the max value you can set is 3049 > under my testing with node v11.15.0 and windows 10

  • if you set it to 3050, then it will overflow and equal to be set to 1.
  • if you set it to 4000, then it will equal to be set to 51 (4000 - 3049)
Set Memory to Max for Node.js
node --max-old-space-size=3049
Set Memory to Max for Node.js with TypeScript
node -r ts-node/register --max-old-space-size=3049

See: <https://github.com/TypeStrong/ts-node/issues/261#issuecomment-402093879>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchackoView Question on Stackoverflow
Solution 1 - Memory ManagementSampsa SuoninenView Answer on Stackoverflow
Solution 2 - Memory ManagementPiyush KatariyaView Answer on Stackoverflow
Solution 3 - Memory Managementj03mView Answer on Stackoverflow
Solution 4 - Memory ManagementPaul RumkinView Answer on Stackoverflow
Solution 5 - Memory ManagementHuanView Answer on Stackoverflow