Created
March 14, 2017 19:31
-
-
Save DimaSavostianov/dd92a3eb7bf7b499ddd60b246532fcf4 to your computer and use it in GitHub Desktop.
c# webbrowser memory leak SOLUTION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Form1 : Form | |
{ | |
[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)] | |
internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize); | |
[DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)] | |
internal static extern IntPtr GetCurrentProcess(); | |
private void ReNewBrowser() | |
{ | |
webBrowser1.Dispose(); | |
webBrowser1 = null; | |
IntPtr pHandle = GetCurrentProcess(); | |
SetProcessWorkingSetSize(pHandle, -1, -1); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
GC.Collect(); | |
webBrowser1 = new WebBrowser(); | |
//Это уже мои заморочки, но на всякий случай не забудьте про них | |
webBrowser1.Location = new Point(11, 42); | |
webBrowser1.Size = new Size(1054, 659); | |
webBrowser1.ScriptErrorsSuppressed = true; | |
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; | |
webBrowser1.Navigating += webBrowser1_Navigating; | |
splitContainer1.Panel1.Controls.Add(webBrowser1); | |
// конец заморочек | |
webBrowser1.Show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! Solve a lot