• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2392
  • Last Modified:

.Net Release WebBrowser Control (IE Internet Explorer) Memory Leak?

The trivial prototype code below loses memory on every navigate.

I can't believe that IE has a memory leak after all these years.  I've Googled it and there seem to be solutions for earlier .Net versions but they are all very complicated.

Our production code leaks (no joke) 10MB on EVERY navigate!!!  That's egregious!

Any simple ideas?


private void Form1_Load(object sender, EventArgs e) {
            timer1.Interval = 5000;
            timer1.Start();
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
 
private void timer1_Tick(object sender, EventArgs e) {
            webBrowser1.Navigate(new Uri("http://www.somesite.com"));
}

Open in new window

0
ZuZuPetals
Asked:
ZuZuPetals
3 Solutions
 
angus_young_acdcCommented:
You could try invalidating or disposing of the control and recreating it for each navigate.  10MB... blimey :S
0
 
gregoryyoungCommented:
How are you measuring your memory leak?

All too often I hear people yell "memory leak" without there being one.

Thanks,

Greg
0
 
ZuZuPetalsAuthor Commented:
I tried creating an additional form and calling Dispose() on it... no effect.

I'm measuring the leak by watching Windows Task Manager /Processes\ in the "Mem Usage" column... it goes from 38,000K up to 200,00K.
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
ZuZuPetalsAuthor Commented:
Seems to be a bug with the Internet Explorer control and there is no solution.
0
 
gregoryyoungCommented:
ok ... you understand that under task manager mem usage you are looking at working set not actual memory used right?

Also you understand that garbage collection may take a while to release certain things.

0
 
John ClaesCommented:
Solution is now known (works for me)

-- in class definition

        [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();

-- code to call when you want to reduce the memory

            IntPtr pHandle = GetCurrentProcess();
            SetProcessWorkingSetSize(pHandle, -1, -1);
0
 
AgentPlatformCommented:
It doesn't work for me. Just navigate many times to the link that has flash like: http://www.nhaccuatui.com/nghe?M=zIU2SKFEGT
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now