How to increase the max memory limit for the app built by electron-builder?

旧城冷巷雨未停 提交于 2019-11-30 13:15:06
user1349923

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', () => {
    // ...
});

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!