chacko
chacko

Reputation: 5164

memory limit in Node.js (and chrome V8)

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.

Upvotes: 100

Views: 175420

Answers (5)

Paul Rumkin
Paul Rumkin

Reputation: 6873

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.

Upvotes: 2

Piyush Katariya
Piyush Katariya

Reputation: 765

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

Upvotes: 37

Huan
Huan

Reputation: 3237

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

Upvotes: 3

j03m
j03m

Reputation: 5303

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 :).

Upvotes: 6

Sampsa Suoninen
Sampsa Suoninen

Reputation: 624

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

Upvotes: 29

Related Questions