1

Is pretty well known that the WebBrowser control will on some cases increase its memory usage without releasing it. And extreme case is when navigating through pages in Google while Google Instant is on. It will grow by about 3 MB per page. This memory won't be released even if I navigate to about:blank or if I dispose the WebBrowser.

I know the memory in the Task Manager is not reliable, and there are many ways of checking the memory my application is consuming, but since what I really care about is preventing my application from crashing, I'm using the MemoryFailPoint class to figure out how much memory I have left. And as my previous result, I'll have about 3 MB less per page to use.

The last test I did was to create a form in my application where there is only a WebBrowser, perform a search in Google with Google Instant on, and then automatically navigate to the next page every 3 seconds. The memory left will decrease and when is close to 100 MB, I'll close the form (which will dispose the WebBrowser) and see that the memory left stays the same. I also used SOS to make sure the WebBrowser had been disposed properly.

GC.Collect() and these kind of tricks won't release the memory. Installing IE 8 or IE 9 won't do either. I don't want to list all the things I've tried because it would make this question way too long. I've even contacted Microsoft's paid support to no avail.

On the other hand, closing and restarting the application will release the memory. So the closest I've got so far to a definite solution to this problem is restarting the application.

So my question is, how can I get as close as possible to restarting the application without actually restarting it? I'm considering running the WebBrowser on a separate process and restarting it as necessary. The problem with this is that I'd need to have it on another form which would mess up my application's UI.

I'm thinking there should be a way to tell the WebBrowser "please go away I really don't want you anymore!" by perhaps unloading whatever dll is consuming all this memory and then reloading it. I'm looking for extreme measures.

Please, notice that this question is not the same as my previous one. What I need to know here is not how to release the memory used by the WebBrowser (since this is not possible, or at least there is no known solution), but, in general, if there is a way to run a control in a "sandbox" and then clear this sandbox. Pretty much like running it in a separate process.

Any ideas?

Community
  • 1
  • 1
Juan
  • 15,274
  • 23
  • 105
  • 187

1 Answers1

1

Check for event handlers... if you don't remove them before closing the form they could hold on and prohibit the WebbRowser control from really being disposed...

You can try several things:

Yahia
  • 69,653
  • 9
  • 115
  • 144
  • Already tried most of this. Checked event handlers (also used SOS to make sure the `WebBrowser` was already gone) and tried your first point. But I really wouldn't take the time to try to migrate to `csEXWB` because already read about it having leaks, plus it is also based on IE so it will most likely have the same leaks, plus it has 0 technical support, _etc_. But awesomium looks promising. I'll give that a try and report back :). – Juan Oct 16 '11 at 06:20