JavaScript heap out of memory

Everything works fine when I debug and run my app on one device.
But ss soon as I add another device or 2 more (so total of 3), and after a couple of save + hot-reloads, i get the error below.
I basically want to make UI changes and see them render on different OS’s and versions at same time.
Is that possible? I definitely have enough RAM on my PC.

Building JavaScript bundle: finished in 926ms.
FATAL ERROR: Ineffective mark-compacts
near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF7ACE7F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
2: 00007FF7ACE5A0C6 node::MakeCallback+4518
3: 00007FF7ACE5AA30 node_module_register+2032
4: 00007FF7AD0E20EE v8::internal::FatalProcessOutOfMemory+846
5: 00007FF7AD0E201F v8::internal::FatalProcessOutOfMemory+639
6: 00007FF7AD602BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
7: 00007FF7AD5F9C46 v8::internal::ScavengeJob::operator=+24310
8: 00007FF7AD5F829C v8::internal::ScavengeJob::operator=+17740
9: 00007FF7AD5F7765 v8::internal::ScavengeJob::operator=+14869
10: 00007FF7AD601064 v8::internal::Heap::MaxHeapGrowingFactor+2548
11: 00007FF7AD1BCA3B v8::internal::factory::AllocateRawWithImmortalMap+59
12: 00007FF7AD1BF4ED v8::internal::factory::NewRawTwoByteString+77
13: 00007FF7AD29B5EB v8::internal::EhFrameIterator::Done+51947
14: 00007FF7AD5CD0D9 v8::internal::interpreter::operator<<+57001
15: 00007FF7AD5CB372 v8::internal::interpreter::operator<<+49474
16: 00007FF7AD5C97AD v8::internal::interpreter::operator<<+42365
17: 00007FF7AD5C9F6E v8::internal::interpreter::operator<<+44350
18: 00007FF7AD5CC28E v8::internal::interpreter::operator<<+53342
19: 00007FF7AD5C97AD v8::internal::interpreter::operator<<+42365
20: 00007FF7AD5C67E8 v8::internal::interpreter::operator<<+30136
21: 00007FF7AD2A8326 v8::internal::CodeStubAssembler::ConstexprBoolNot+39286
22: 00007FF7AD2A821B v8::internal::CodeStubAssembler::ConstexprBoolNot+39019
23: 000000A2500DC721

expo diagnostics:

Expo CLI 3.4.0 environment info:
OS: Windows 8.1
Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD


This article might help, although it’s not specifically about Expo:

In addition to the above, node uses the NODE_OPTIONS environment variable to set options globally, so you could try setting the NODE_OPTIONS environment variable to e.g. --max-old-space-size=4096 and see if that improves the situation.

You might want to also try upgrading node to see if that makes a difference.

Thank you for the feedback, but where exactly do I run this command? I usually run expo start in my project’s root folder. I assume that is using node, so do i have to attach to that somehow? And do i have to run this every time, or can i increase the limit once (and maybe globally)?

thanks in advance

This article might help.

Basically you would create a variable called “NODE_OPTIONS” and set the value to “--max-old-space-size=4096” (without the quotes).

Then open a new terminal window and test if the variable is available like this:

C:\> echo %NODE_OPTIONS%

That should print out --max-old-space-size=4096

If it still runs out of memory, try a larger number when setting the variable.

Setting the variable as in the above article is global and permanent (until you delete the variable again.) You should be able to run expo start etc. as usual.

thank you for the suggestion. i tried that and created a new variable and verified that i was set with the echo command. but the issue is still there :frowning: node runs out of memory around 1.3GB
do you think there is another way to set it?

Sorry, I don’t. The only things I can think of are:

  1. Only processes started after setting the environment variable will pick up the change. In theory this is not a problem because you verified in the terminal window that it was set before running expo start, but maybe just reboot to be sure.
  2. I’ve seen some mentions of --max_old_space_size=4096 (with underscores instead of dashes). As far as I know either one is acceptable, but maybe try with underscores just in case.
  3. Try a bigger number when setting the environment variable.
  4. Maybe see if there’s a nodejs forum where people might have more ideas to troubleshoot/fix this.

Yeah, as wodin more-or-less has it right. 1.3~1.4 GB is the default maximum amount of memory that V8 allocates, and you need to pass the poorly documented --max_old_space_size option to get around it. --max_old_space_size=4096 should get you 4 GB.

So, how do you actually use this? If you’re calling node directly, you do node --max_old_space_size=4096. However, you’re probably using node indirectly through something else so you need to use the NODE_OPTIONS environment variable. Since you’re using MS Windows, I’d recommend using cross-env. If you’re using npm, you can do something like the following:

npm i -D cross-env
# add the following to "scripts" in package.json
# "start": "cross-env NODE_OPTIONS=--max-old-space-size=4096 expo start"
npm run start

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.