How to increase the max memory limit for the app built by electron-builder?
Just wanted to add that, in my case, the max-old-space-size
flag was only being successfully applied when I placed it in my webview's "preload" script, like so (Start_WebviewPreload.ts):
import {remote} from "electron";
remote.app.commandLine.appendSwitch("js-flags", "--max-old-space-size=8192");
Placing it in the "main.js" file (the entry point of the whole program), did not do anything. (I even checked the command-line arguments using Process Hacker 2 and it didn't show any of the electron processes as having that flag until I moved the code as mentioned above)
Also, I notice that there may be some kind of race condition between the setting of the command-line flag and the execution of app.on("ready")
-- some of the time, the code above works for the main renderer process (the one not-in-the-webview), whereas other times it doesn't.
So basically: If you want to ensure your command-line switches work, apply them within the preload script for the given browser-window/web-view.
In main.js, add:
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
According to Supported Chrome Command Line Switches, this should be called before the ready
event is emitted. For example:
import { app } from "electron";
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
app.on('ready', () => {
// ...
});