How to Fix the Memory Leak in IE WebBrowser Control?

my app was also constantly consuming memory when navigating, and not releasing anymore.
i fount the solution for me here:
http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8

for completeness ill post the notable excerpt:

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

all honors to:
http://social.msdn.microsoft.com/profile/mike_t2e/?type=forum&referrer=http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8
for posting the solution.

and
http://ict-engineer.blogspot.com/2010/10/net-webbrowser-control-memory-leak.html
for SEO’ing it right, so i could find it 😉

greetings

edit: if this helps you to quickly solve an issu – good. but you should overthing your application design, the pattern you use if any , refactore the thing if you build onto that much longer ….

Leave a Comment