views:

964

answers:

5

Is there a way to find out the memory usage of each dll within a c# application using com dll's? Or what would you say is the best way to find out why memory grows exponentially when using a com object (IE. Whether the COM object has a memory leak, or whether some special freeing up of objects passed to managed code has to occur(and/or how to do that)).

A: 

dotTrace rocks: http://www.jetbrains.com/profiler/

Keep in mind that all COM objects in .NET are basically MarshalByRefObject-derived classes at heart, so you should be able to look for memory consumption by such objects as one potential filter.

EnocNRoll
+1  A: 

A Microsoft support engineer has a fabulous blog that walks through lots of cases like this. She goes over all the tools she uses. I found it extremely helpful to read through all of her posts when I was debugging this kind of stuff a few years ago.

Edit: Apparently, she has added a series of labs that explain how to setup your environment and diagnose different problems. You may want to start here.

twk
A: 

First thing I'd want to do is be absolutely certain that I'm not leaking references anywhere, then go into the smallest steps that will reproduce the steps (a good profiler is essential, I happen to use and recommend RedGate's ANTS Profiler) -- it can be done, and it is worth sending example code that reproduces the issue to the vendor of the COM object so they can resolve it (There is actually a hotfix for Crystal Reports as a result of a memory leak in it which I found :)

Rowland Shaw
+2  A: 

Are you releasing the COM object after usage(Marshal.ReleaseComObject)?

What type of parameters are you passing in/out of the calls?

If you don't have the COM object source code and want to determine why its 'leaking', Run the COM object outa proc, attach WinDBG to the process and set breakpoints on memory allocation APIs(HeapAlloc,etc...). Look at the call stack and allocation patterns. Sure you can use profilers on the managed side but if you want to know what is going on you are going to have to get your hands dirty...

Matt Davison
Hopefully, a profiler will give you the info you need in order justify going deeper.
EnocNRoll
A: 

Try this tools for profiling your code :
http://www.softprodigy.net/
Source code also available for download.

More one link for you : Static Analysis Tools For .NET, Matt Berseth’s Blog

lsalamon
softprodigy simply didn't run for me :-(
Orion Edwards