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

前端 未结 2 1881
生来不讨喜
生来不讨喜 2020-12-31 12:29
  • Version: \"electron\": \"1.6.2\", \"electron-builder\": \"^16.8.2\",
  • Target: windows x64

I know I can add

相关标签:
2条回答
  • 2020-12-31 13:13

    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.

    0 讨论(0)
  • 2020-12-31 13:27

    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', () => {
        // ...
    });
    
    0 讨论(0)
提交回复
热议问题