I am creating an app packaged/wrapped via electron.js consisting of a node.js part and some services, and a react frontend.
I am trying to make the application start with more heap space (more RAM memory assigned). But as far as goes, all efforts are not working.
Options I tried:
Everything did not seem to have any effect whatsoever ! (References: https://github.com/electron/electron/issues/2056, https://warpdesign.fr/electron-development-how-to-configure-nodejs-and-runtime-chrome-flags https://www.geeksforgeeks.org/command-line-arguments-in-electronjs/ )
The memory keeps being fixed to 2 GB ( output MAX HEAP SIZE (bytes): 2132773076 ~ 1.99 GB ) Also, when outputting what is in the process.env, there is a NODE_OPTIONS: '--max-old-space-size=4096' ... so in some way it is picked up ??? But never applied to the embedded node.js.
How can I force this to increase it heap space ? I tried all suggestions. Is that broken in electron ? or am I still doing something wrong ?
These steps will help you out, please try them.
app.commandLine.appendSwitch
const { app } = require('electron');
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
app.on('ready', () => {});
NODE_OPTIONS="--max-old-space-size=4096" electron .console.log(require('v8').getHeapStatistics().total_available_size);The max-old-space-size configuration you are trying to set needs to be set before the process initializes itself. By using the command line flags or trying to set the env variable while the process is already running, the process has already passed the stage where setting the space size can occur.
As per the docs (which explicitly use --max-old-space-size in the example):
Certain Electron behaviors are controlled by environment variables because they are initialized earlier than the command line flags and the app's code.
So your only option to is figure out a way to set the environment variable for your electron executable after packaging. It's possible that whichever packaging option you're using (electron-forge, electron-builder, etc) has this configuration, but you'd have to comb the related documentation for it (a cursory glance by me didn't reveal what you need).
How you achieve this will entirely depend on your use case, one option if you are installing on a linux system and intend to launch from terminal, is using your install script to set up an alias in the user's profile like
alias myapp='NODE_OPTIONS="--max-old-space-size=4096" /usr/local/bin/myapp.electron'
A similar approach (prepending the env variable to the executable call) would work for setting up a desktop icon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With