WebBrowser memory problem

无人久伴 提交于 2019-11-28 11:22:48

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.

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.

womd

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 )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!