1

I've been having some trouble using Web Browser Control, my program continues to scroll down the page forever scraping data.. or until I get a OutOfMemoryException, even though I have plenty of RAM left.

I was thinking after so much scrolling, I should dispose of the Web Browser and then "re-create", or "reuse" again, releasing all previous memory used by it.

When i try to dispose of it through, WebBrowser1.Dispose()

I can then no longer navigate using WebBrowser1.Navigate(URL)

How would I be able to use it, or re-create WebBrowser1 after disposing of it.

Any help would go a long way, thank you.

Jack Trowbridge
  • 3,175
  • 9
  • 32
  • 56
  • 1
    Please show us the code or part of the code what you have tried. – Mukul Varshney Oct 24 '16 at 05:19
  • My whole code is over 3000 lines long, it just consistents of reading WebBrowser1 document HTML over and over again ever 10 seconds or so, while scrolling down the page.. after a long time of scrolling I get a OutOfMemoryException, my research pointed me towards releasing the memory used after so long, which makes sense, but when I call WebBrowser1.Dispose, I can then no longer use it. – Jack Trowbridge Oct 24 '16 at 05:22
  • without seeing code its a bit difficult what went wrong. Anyway, my suggestion is save the result of web response in txt file and try to analyze the response length. How many characters of data is shown on the editor. I mean why you need to scroll so down. – Mukul Varshney Oct 24 '16 at 05:46
  • 1
    You are releasing the control's memory, of course you won't be able to automatically use it after that. To do so you must instantiate a new instance of it after it's disposed. As for your memory concerns, you could either make your app a 64-bit app or [**see this comment from Hans Passant**](http://stackoverflow.com/questions/40108722/microsoft-visual-studio-2015-increase-max-process-memory-over-2gb#comment67489745_40108722). – Visual Vincent Oct 24 '16 at 05:50
  • 1
    My program uses about 800MB before it crashes and points to WebBrowser1 when its reading its document in one of many functions, with a OutOfMemoryException. My program scrolls down the Facebook Newsfeed, scraping data from each and every ad.. after a while of scrapping, around 200 pieces of content later, it crashes. – Jack Trowbridge Oct 24 '16 at 13:15
  • Did you try with Mozilla activeX control instead? http://stackoverflow.com/questions/21336945/how-to-create-simple-browser-with-mozilla-activex-control-with-vb-net – fedeteka Jan 27 '17 at 13:10
  • Another solution http://stackoverflow.com/questions/8302933/how-to-get-around-the-memory-leak-in-the-net-webbrowser-control check "Protected Sub disposeBrowers()" – fedeteka Jan 27 '17 at 13:13

1 Answers1

2

Try it before use WebBrowser1.Navigate(URL):

WebBrowser1 = New WebBrowser
Zserigta
  • 52
  • 9