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
It seems the Navigate() method keeps all the visited pages in memory as you can use the GoBack() method, there is no "memory leak" in fact. My program visits the same Url repeatedly. The "memory leak" problem can be eliminated by using the Refresh() method instand of Navigate() method, followed by a GC.Collect(). The Code is in the following:
try
{
if (webBrowser.Url.Equals("about:blank")) //first visit
{
webBrowser.Navigate(new Uri("http://url"));
}
else
{
webBrowser.Refresh(WebBrowserRefreshOption.Completely);
}
}
catch (System.UriFormatException)
{
return;
}
System.GC.Collect(); // may be omitted, Windows can do this automatically