95

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.

9
  • 9
    What in the world could take up 4GB in JS objects? Aug 25, 2011 at 17:29
  • 52
    @dominic-barnes: Images. Movies. Heck, does it matter? Something will, someday. A MMORPG, for example. I agree that the limitations are brutal, and it was a serious programmer mistake to use 32-bit ints for addressing in the original draft of v8. Aug 25, 2011 at 18:39
  • 5
    you said: "If you want to have 4gb of data you can't do it as JS objects." If that statement is true (and is going to hold true for a while) I'd think nodejs is all hype. Hence I hope you are wrong.
    – chacko
    Aug 26, 2011 at 10:28
  • 6
    I easily move around 8GB in nodejs objects, just for reference. I think a lot has changed in the last few years since this question was asked.
    – user993683
    Apr 9, 2017 at 12:09
  • 4
    There's no memory limit as long as you stream your data. Read & write streams are a great design pattern that will help you do what you need without blowing the V8 memory. Nov 27, 2017 at 12:17

5 Answers 5

33

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
1
29

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

3
  • 9
    I still (even with 64bit) need to specify that I want more memory with the --max-old-space-size=10000 (for 10GB) option, else I get "FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory" at ~1.7GB memory usage in task manager on Windows. Jan 15, 2015 at 0:01
  • 1
    I'm using 8gb+ easily in v7.8.0 - just wish my machine had more RAM
    – user993683
    Apr 9, 2017 at 12:11
  • the link is broken
    – Stav Alfi
    Aug 2, 2021 at 9:44
6

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

0
3

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

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.