How to Fix the Memory Leak in IE WebBrowser Control?

后端 未结 18 943
走了就别回头了
走了就别回头了 2020-11-27 05:33

I am trying to embed a WebBrowser Control in a C# Winform Application. This sounds easy enough. However I discovered that the WebBrowser control eats up a lot of memory ever

18条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 05:43

    Paste the following code after page load

    System.Diagnostics.Process loProcess = System.Diagnostics.Process.GetCurrentProcess();
    try
    {
         loProcess.MaxWorkingSet = (IntPtr)((int)loProcess.MaxWorkingSet - 1);
         loProcess.MinWorkingSet = (IntPtr)((int)loProcess.MinWorkingSet - 1);
    }
    catch (System.Exception)
    {
         loProcess.MaxWorkingSet = (IntPtr)((int)1413120);
         loProcess.MinWorkingSet = (IntPtr)((int)204800);
    }
    

提交回复
热议问题