Jacob Wischnat
Jacob Wischnat

Reputation: 93

Enabling Manual Garbage Collection in Electron app

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?

Upvotes: 9

Views: 5037

Answers (1)

Hans Koch
Hans Koch

Reputation: 4491

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.

Upvotes: 8

Related Questions