How to release memory used by application

M

Mullin Yu

I write a Windows Application which uses db connections and some COM dll.
After running consecutively for 12 hours, the memory of the application
increased from 30MB to 130MB.

How can I trace the main cause of the memory used and how can I release
them?

Thanks!

Mullin
 
D

Dmitriy Lapshin [C# / .NET MVP]

Try to explicitly release COM objects through Marshal.ReleaseComObject().
Please note that ANY reference to an instance released through
Marshal.ReleaseComObject() becomes invalid, not only the reference passed as
the argument.
 
M

Mohamoss

Hi Mullin
You can always use the GC.collect() method which forces the Garbage
collector to do a memory collection instantly . however, this is not the
best practice since the garbage collector (GC) should do collection on its
own at the best suited time according to its algorithm. There might be
something with your application that use memory in a way that is very
efficient ( for example you may be using string object instead of
stringBuilder for extensive string operations ) .
The best way to know what exactly is wrong with your program is to use the
CLR profiler . it is a tool that allow you to see how your program manage
memory ( see this link
http://msdn.microsoft.com/isapi/gomscom.asp?TARGET=/downloads/details.aspx?F
amilyId=86CE6052-D7F4-4AEB-9B7A-94635BEEBDDA&displaylang=en )
Even if you are not a very expert user of CLR you will be at least able
to see what are the object that are in your memory ( and from these you can
know what code allocate these objects and what is wrong with it ). Try to
get the tool from the link and start using it to analize your program and
if you have any question on the tool please post it and I will be looking
back on this thread to see if I can help with anything
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top