Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runaway memory and page file usage.

Status
Not open for further replies.

jazzdrive3

IS-IT--Management
Feb 13, 2007
14
US
Our C# application currently involves opening a form and closing that form as a regular action. However, everytime we close the form, if you look in the task manager, you can see the memory usage go up about 50 MB. The windows page file usage goes up as well.

If we do this about 40 - 50 times, we get an OutOfMemory exception, and the program crashes. We suspect that the GC cannot free the resources, as something may still be subscribed to the form, and keep the memory from being reallocated.

Is there a debugging tool that could help us track this down? It's like looking for a needle in a haystack. We're using VS.NET 2005.

Thanks.
 
Can you describe your application and what it does? What does it work with?

Are you using unmanaged resources such as images?
 
We are actually using a lot of images: PNG's and bitmaps. Also .wav files.

Our application runs kiosks, so it talks with hardware like bill acceptors. But all the hardware is managed in a separate .dll, and the main app just calls it.

Thanks.
 
You coul use a memory profilre like .net profiler that will show you the difference between two states. For example before you open your app and after you open and then after you close. This way you can see which objects don't get collected.

Christiaan Baes
Belgium

"My new site" - Me
 
We'll give it a shot. Thanks. What can typically be done once we know which objects are not getting collected?
 
Chances are good you are not calling Dispose() on your images. Go into the Dispose method of any control that contains images. When you are disposing, dispose the images before the controls.

Code:
private Image myimg = Image.FromFile("myimage.bmp");


protected override void Dispose( bool disposing )
		{
			if( disposing )
			{

                              myimg.Dispose(); <-- HERE!

				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
 
We're already calling Dispose on all of our images.
 
Try running FxCop against your application. It will help identify where you're missing a call to Dispose().

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top