90

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.

chacko
  • 5,004
  • 9
  • 31
  • 39
  • 9
    What in the world could take up 4GB in JS objects? – Dominic Barnes Aug 25 '11 at 17:29
  • 51
    @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. – Elf Sternberg Aug 25 '11 at 18:39
  • 1
    If you want to have 4gb of data you can't do it as JS objects. Maybe this link can help? https://developer.mozilla.org/en/javascript_typed_arrays – goatslacker Aug 26 '11 at 00:38
  • 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 '11 at 10:28
  • @Dominic Barnes - calling out to a shared lib with ffi which uses a lot of memory – Ben Burns May 15 '14 at 02:56
  • 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. –  Apr 09 '17 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. – Wallace Sidhrée Nov 27 '17 at 12:17
  • 2
    9 years have passed and not a single clear answer to this simple question – joniba Aug 05 '20 at 12:23
  • Serious java developers these days, split up their code in many small microservices and they have tons of overhead to accomplish this, because java was designed in a pre-internet ERA. Node.js actually is a programming language that is DESIGNED to be a microservice language. The reason why you're hitting these memory boundaries is because you're using it to build a monolith, or even worse, a monolith with an internal cache. If you're trying to build a cache take a look at Elastic or Redis and let it do the caching for you. If you're building a monolith, then split it now before it's too late. – bvdb Nov 10 '21 at 19:16

5 Answers5

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

Sampsa Suoninen
  • 624
  • 4
  • 9
  • 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. – Andreas Reiff Jan 15 '15 at 00:01
  • 1
    I'm using 8gb+ easily in v7.8.0 - just wish my machine had more RAM –  Apr 09 '17 at 12:11
  • the link is broken – Stav Alfi Aug 02 '21 at 09:44
28

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
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Piyush Katariya
  • 655
  • 8
  • 11
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 :).

j03m
  • 5,195
  • 4
  • 46
  • 50
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

Huan
  • 2,876
  • 3
  • 30
  • 49
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.

Paul Rumkin
  • 6,737
  • 2
  • 25
  • 35