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

Posted on 2009-02-24
Last Modified: 2013-12-17
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;


            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);


private void timer1_Tick(object sender, EventArgs e) {

            webBrowser1.Navigate(new Uri(""));


Open in new window

Question by:ZuZuPetals
    LVL 15

    Assisted Solution

    You could try invalidating or disposing of the control and recreating it for each navigate.  10MB... blimey :S
    LVL 37

    Assisted Solution

    How are you measuring your memory leak?

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


    LVL 2

    Author Comment

    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.
    LVL 2

    Accepted Solution

    Seems to be a bug with the Internet Explorer control and there is no solution.
    LVL 37

    Expert Comment

    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.

    LVL 10

    Expert Comment

    by:John Claes
    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);

    Expert Comment

    It doesn't work for me. Just navigate many times to the link that has flash like:

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now