Where all my memory has gone?

  • Thread starter Thread starter Muscha
  • Start date Start date
M

Muscha

My c# application has gone beserk, it consumes 700MB memory griding my
machine to a halt. What is the quickest way for me to find out what's
happening? Where do all the memory has gone?

/m
 
My c# application has gone beserk, it consumes 700MB memory griding my
Use a profiler to find the memory leak.

I think this one is good:

http://www.scitech.se/memprofiler/

Thanks,

but now I notice that when I'm doing GC.GetTotalMemory(true) the amount of
memory is much less than the memory that I see in task manager. The
difference can be really big, for example:

GC.GetTotalMemory() shows 8MB
Task manager shows 120MB!

This is really odd, does anyone know anything about this?

thanks,

/m
 
If you minmize the main form , how much memory is used ?

If the memory usage is still large , it's could be that unmanaged resouce is
not released . Other reason could be that too many control is showing in
your form.

Regards,

Phlics
www.phlics.com
 
Muscha,
are you doing any large string concatination such as:

string blah = "";
blah += "A whole bunch of stuff";

This has been known to eat some memory ,if you are working with huge
strings. if so you may want to change over to using the stringbuilder class.

It is hard to tell what it could be. are you using any COM objects in your
app?
 
Ah finally found the problem. It was a loop in importing an XmlNode into
another XmlDocument ie:

foreach (XmlNode node in metadata.XmlDocument.DocumentElement.ChildNodes)

{

XmlNode toBeImportedNode = this.Metadata.XmlDocument.ImportNode(node,
true);

this.Metadata.XmlDocument.DocumentElement.AppendChild(toBeImportedNode);

}



But!! There was a bug in my code that make this.Metadata = metadata, thus
each element is added to itself and the foreach loop never finishes. Jeez ..
stupid me :) And XmlDocument consume so much memory no wonder in a blink the
RAM shot up to 700Mb!

/m
 
Back
Top