I have been trying to get Garbage Collection and Max Old Space Size configured in our compiled and built Electron app.
I am able to debug with these settings on through the CLI electron.cmd --js-flags="--expose_gc --max-old-space-size=128" .
and the Global GC is available.
However when I try and use the electron API app.commandLine.appendArgument('--js-flags', '--expose_gc --max-old-space-size=128');
to set these flags it doesn't enable GC as expected, this code is being called before the app.on('ready', ...)
function.
Nor does setting NODE_OPTIONS help (I see that this has been disabled in the latest Electron version as per here: https://github.com/electron/electron/issues/12695)
Does anyone have experience getting this working?
Luckily for you, Node. js comes with a garbage collector, and you don't need to manually manage memory allocation.
If you launch the node process with the --expose-gc flag, you can then call global. gc() to force node to run garbage collection. Keep in mind that all other execution within your node app is paused until GC completes, so don't use it too often or it will affect performance.
JavaScript values are allocated when things are created (objects, Strings, etc.) and freed automatically when they are no longer used. This process is called Garbage collection.
app.commandLine.appendSwitch('js-flags', '--expose_gc --max-old-space-size=128')
The first argument of appendSwitch does not use the --
prefix, just drop that. The seconds argument is parsed as is, thats why it keeps the prefix.
Also be aware it only exposes gc for the renderer if you use apppendSwitch, if you want to use it there you will need to add the CLI argument.
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