Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to increase electron max memory limit (--max_old_space_size) #2056

Closed
bu2 opened this issue Jun 25, 2015 · 11 comments
Closed

How to increase electron max memory limit (--max_old_space_size) #2056

bu2 opened this issue Jun 25, 2015 · 11 comments

Comments

@bu2
Copy link

bu2 commented Jun 25, 2015

Is it possible to use the V8 option --max_old_space_size=N to increase the max memory limit of the electron process and its BrowserWindow subprocess ?

I tried different commands without success (I am on Mac OS X with node installed with Homebrew and electron installed with npm):

$ electron --max_old_space_size=4096 app/
$ node --max_old_space_size=4096 ~/.brew/bin/electron app/
...

(I also tried --max_old_space_size and --max-old-space-size).

I reach the limit around 1.5~1.7Go of memory when the following error occurs:
[1765:0625/153220:ERROR:atom_bindings.cc(32)] Fatal error in V8: CALL_AND_RETRY_LAST Allocation failed - process out of memory

I am brute testing with following main.js program:

var output = [];
var count = 0;

while (true) {
  output.push(new Object());
  count++;

  if (count % 1000 == 0)
    console.log(process.memoryUsage());
}

Regards,

Bruno.

@zcbenz
Copy link
Member

zcbenz commented Jun 25, 2015

Does --js-flags="--max_old_space_size=4096" work for you?

@bu2
Copy link
Author

bu2 commented Jun 25, 2015

Sorry but it does not work. I tried:
electron --js-flags="--max_old_space_size=4096" app/
and
node --js-flags='"--max_old_space_size=4096" ~/.brew/bin/electron alpha/

It work correctly for a pure nodejs program with following command:
node --max_old_space_size=4096 alpha/main.js

@bu2
Copy link
Author

bu2 commented Jun 25, 2015

The option --js-flags="--max_old_space_size=4096" works on electron build from source following instructions: http://electron.atom.io/docs/v0.28.0/development/build-instructions-mac.

I run with following command:
$ ~/lab/atom/electron/out/R/Electron.app/Contents/MacOS/Electron --js-flags="--max_old_space_size=4096" ./app/

My config:
macbook pro 13 early-2015
OS X 10.10.3

From my point of view, you can close this issue.

Thank you.

@zcbenz
Copy link
Member

zcbenz commented Jun 26, 2015

👍

@zcbenz zcbenz closed this as completed Jun 26, 2015
@mgcrea
Copy link

mgcrea commented Dec 5, 2016

Sorry to revive an old thread, but it looks like --js-flags="--max_old_space_size=4096" does not work anymore with latest electron, do you know if it got somehow replaced by another flag in latest electron?

@jrieken
Copy link

jrieken commented Jun 6, 2017

@zcbenz Can you comment on the differences how this flag behaves when having ELECTRON_RUN_AS_NODE set? It just seems to be ignored in that case? Given a script that just allocates memory (microsoft/vscode#28112 (comment)) I can see the option nicely when running like this:

./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron --js-flags="--max_old_space_size=2024" ~/Desktop/big.js

but when running it like so it is ignored

 env ELECTRON_RUN_AS_NODE=true ./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron --max_old_space_size=2024 ~/Desktop/big.js

Using the latter variant with nodejs (8.0.0) is working and shows the desired effect. What is different in electron?

@botezatumihaicatalin
Copy link

botezatumihaicatalin commented Aug 1, 2017

I got it to work like this by inserting this piece of code in Browser.js before ready event:

app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096')

@Hadatko
Copy link

Hadatko commented Jan 21, 2019

Hello could you address location of that file? I found several Browser.js

@hexianzhi
Copy link

hexianzhi commented Nov 19, 2019

In win10, electron 2.0.13, app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096') is not working.

but you can add --js-flags=--max-old-space-size=500 in packge.json scripts:

{
  "scripts": {
    "start": "electron --js-flags=--max-old-space-size=500 . "
  }
}

Or if you use electron-vue, change two part:
dev-runner.js:

function startElectron () {
  var args = [
    // Add the line below,this for electron.exe
    "--js-flags=--max-old-space-size=500",
    '--inspect=5858',
    path.join(__dirname, '../dist/electron/main.js')
  ]
}

packge.json :

{
  "scripts": {
     // This for node.js
     "dev": "node --max-old-space-size=4096 .electron-vue/dev-runner.js",
  }
}

@Hadatko
Copy link

Hadatko commented Nov 19, 2019

Hi,
i am using this: "node_modules/.bin/electron --js-flags='--max-old-space-size=10192' ."

@Akash9773312
Copy link

Hi I am using electron 23.1.1 and I facing an Out Of Memory error can be please address me how can I resolve the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants