Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Resolving memory leak in .NET WebBrowser control

Posted on 2008-10-29
12
Medium Priority
?
3,672 Views
Last Modified: 2013-12-17
I have a C# desktop app (VS.NET 2005) which contains a form with a WebBrowser control on it.  Whenever I click on a link in the WebBrowser control, though, it uses memory.  Eventually, my app is consuming a large amount of memory that isn't released unless I close the program.

Any suggestions or alternatives to the WebBrowser control?  I have a deadline approaching, and need to resolve this.  Thank you all so much!  If you need further details, let me know, and I'll post them.
0
Comment
Question by:C_Sharp_Programmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22829599
Is the WebBrowser control viewing a page that you have created?

Do the pages being viewed contain JavaScript?
0
 
LVL 4

Author Comment

by:C_Sharp_Programmer
ID: 22833147
No, the page isn't one that I created; it doesn't matter what page I load in it...

Yes, I believe the page in question does have JavaScript on it... I've read that this can be an issue with the WebBrowser control; is there any way to deal with this, or is there an alternative to the WebBrowser control?
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22833335
Does the memory leak appear to occur if you point it at this website?

If it does then you could try to collect your garbage using a timer, say every minute.

public void timer1_Tick(object sender, EventArgs e)
{
   GC.Collect();
}

There isn't an alternative that I am aware of. I did a search for you and was hoping to find a FireFox one. I will keep an eye out for alternatives because this is something that I too would be interested in (but for different reasons).
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 4

Author Comment

by:C_Sharp_Programmer
ID: 22834312
The garbage collection doesn't seem to work...

I tried loading this site, and just navigating around it used up 5,000K memory...
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22834551
The WebBrowser control does need a lot of memory to run, but you should notice that it stops acquiring more memory at some stage. Do you think it would have exceeded 5,000K if you continue to look at more websites?

On my system the memory usage of a form with a WebBrowser control on it uses up to about 50,000K after clicking around a bit. But when it hits that amount it tends to drop again to 46,000K. The program started at about 23,000K and progressed onwards from there.

I then tried adding a timer with a 1 second interval, and called GC.Collect() to compare the results. This time the program started at about 24,000K and reached a maximum of 36,000K after the same number of menu items. Whenever it got to that amount it dropped down to around 26,000K.

What technique are you using to measure memory usage? I use "Process Explorer".
0
 
LVL 4

Author Comment

by:C_Sharp_Programmer
ID: 22834645
I've used the Windows Task Manager and Process Explorer...

For some reason my app doesn't release the memory.  I have a timer that refreshes the page / clicks a link ever so often.  When I first start the program, it's typically using 70,000K of memory... If I check it six hours later it's using 500,000K.  Even if I stop the timer and manually navigate to another website, the memory isn't released unless I exit the program completely.
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22834704
What version of IE are you using? Do you have a lot of plugins installed in IE?

I believe that the WebBrowser control is essentially an instance of IE.
0
 
LVL 13

Accepted Solution

by:
numberkruncher earned 1500 total points
ID: 22834816
After some more tries it turns out that the garbage collection is not having a bearing. However, each time I try it kind of selects a different maximum. Whenever it hits that maximum amount it always drops again. So on this computer it would appear to be working correctly. I am using VS2008 with .NET 3.5.

The only other web browser I have been able to find was a Mozilla ActiveX control  which looks as though it died in 2005 because it hasn't been touched since. A word of caution just in case you came across it; apparently it causes some serious security risks if you have got anything later than FireFox 1.0.

The only alternative I can think of is to create your own .NET wrapper around the Mozilla SDK. This is probably a mammoth task though!
0
 
LVL 4

Author Comment

by:C_Sharp_Programmer
ID: 22835091
I will look into the Mozilla ActiveX control... Basically, I just need something to display an HTML document, so I've been using the WebBrowser control.
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22835242
Have you tried your program on a different computer? If not, it might be worth a try.


I found another web browser ActiveX control; you have to purchase a license, but it looks to be inexpensive.

http://nbit.net.au/vpages.aspx?ID=HTML%20Viewer%20ActiveX
0
 
LVL 4

Author Comment

by:C_Sharp_Programmer
ID: 22872611
Thanks for the assistance.  I found some other alternatives as well.  The first is the Mozilla XULRunner, which is an embedded mozilla solution with the same basic API functionality as IE
https://developer.mozilla.org/en/XULRunner#Community

I also found GecoFX, which is a .NET wrapper for the firefox/gecko browser
http://code.google.com/p/geckofx/

In addition, it looks like WebKit is an alternative as well (the engine that Safari and Google Chrome are built on)
http://webkit.org/building/run.html
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 22872936
Thanks for posting those links, they are quite interesting. The third link might help with a project that I am working on at the moment!
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question