none
WebBrowser RRS feed

  • Question

  • Hi to everyone,

    When I use WebBrowser control'method public void Navigate(string urlString, string targetFrameName, byte[] postData, string additionalHeaders);

    it always takes more and more memory.

    I'm calling it in timely manner, every minute.

    Is it possible to avoid memory leak?

    Seems like it keeps all data and doesn't release it after navigation.

    I tried calling GC without success.

    Any idea, please?
    Monday, November 30, 2009 10:16 AM

Answers

  • Hi,

    If you are using IE7, I recommend you to update it to IE8 as IE7 had severe memory leak issues.

    If this doesn't work for you, you can try to reduce the memory usage by SetProcessWorkingSetSize function:

        [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);
    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Monday, December 7, 2009 3:45 AM
    Thursday, December 3, 2009 8:21 AM