none
AxSHDocVw.AxWebBrowser user control not clearing memory after dispose/force the GC collect. RRS feed

  • Question

  • We have developed a browser user control based on AxSHDocVw.AxWebBrowser from Microsoft, we are seeing a memory issue of memory not released after we dispose the user control, we see the methods are invoked but the memory consumed is not released. also tried GC collect to force it but no effect.

    We have used a memory profiler to see how the memory is categorized, its under un-managed bucket, JScript9 as the component which is consuming the memory and increases for each instance of that control.

    Wondering is there a known issue with the AxSHDocVw.AxWebBrowser control?

    Any ideas how to dispose the user control?

    Any alternative solutions to show the websites/web-apps in a windows application? 

    Tuesday, October 10, 2017 7:57 PM

All replies

  • Hello Aravpal,

    Calling Dispose or GC.Collect won't work for any object that there are references holding on to the object.For example,if you have a static member holding a reference to an object that has a member reference to this control, then the GC won't be able to claim the memory. It's the code relating memory leak.Try and make sure that that is not the case.

                    axWebBrowser.Dispose();
                    axWebBrowser = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
    
                   

    And after search I found some people receive some useful solutions from here.The following is one of good choice.

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

    >>Any alternative solutions to show the websites/web-apps in a windows application?

    A highly rated alternative is to use WebKit.which releases it's allocated memory after you call dispose or when you navigate to another webpage.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 11, 2017 9:51 AM
    Moderator