WebBrowser memory problem

后端 未结 3 985
悲哀的现实
悲哀的现实 2020-12-10 16:54

I have a .NET application that needs uses a WebBrowser to automatically navigate through a bunch of pages. But if I go to, for instance, Google and set Google I

相关标签:
3条回答
  • 2020-12-10 17:18

    I think HtmlElement pnext is not released, since it's ComObject, and there may be a bug in Browser Control.

    Try pnext.Release or try Marshal.Release and get the instance of ComObject to release.

    0 讨论(0)
  • 2020-12-10 17:18

    when working with Webbrowser, i found that it is important to wait for the "documentcompleted" event and check if the "state" is "completed" bevore navigating no next page. Else cancel navigation and wait again for document-completed state (aborted ) bevore navigating....

    could be that the use of timers and not checking the Webbrowser's state could be a problem

    the next thing with the Webbrowser-Control is, that you cannot use it in multithread / Backgroundworker since it requires to be STA....( often makes problems with unresponsive application )

    the solution for "ful-contol" (parsing websites ) using .NET for me, was to use WebRequest / Webresponse , you can cast the result of that to Webbroswer.Document again if you want the DOM to be "auto" executed , use it multithreaded , easyly set timeouts / proxy wich i found more comfortable than using Webbrowser-control.

    Nevertheless i sucessfully implemented a Webbrowser-Control parsing pages in another project using hints from here ( How to Fix the Memory Leak in IE WebBrowser Control?)

    another "funny" thin with Winforms-programming i found out is, that it seems that a GC.Collect is triggered when the window is minimized an opened again - > does this decrease the mem-usage ? ( maybee Stefan's post also references to this issue )

    0 讨论(0)
  • 2020-12-10 17:21

    Windows doesn't really return freed memory if there's nor reason for it. And the only reason would be if another app requires that memory and there's no other memory available anymore. That's why it looks as if the memory use increases.

    Try calling

    SetProcessWorkingSetSize(GetCurrentProcess(), -1, -1);

    sometimes - this will force the OS to return all freed memory back to the OS.

    0 讨论(0)
提交回复
热议问题