I have written various C# console based applications, some of them long running some not, which can over time have a large memory foot print. When looking at the windows perofrmance monitor via the task manager, the same question keeps cropping up in my mind; how do I get a break down of the number objects by type that are contributing to this footprint; and which of those are f-reachable and those which aren't and hence can be collected. On numerous occasions I've performed a code inspection to ensure that I am not unnecessarily holding on objects longer than required and disposing of objects with the using construct. I have also recently looked at employing the CG.Collect method when I have released a large number of objects (for example held in a collection which has just been cleared). However, I am not so sure that this made that much difference, so I threw that code away. I am guessing that there are tools in sysinternals suite than can help to resolve these memory type quiestions but I am not sure which and how to use them. The alternative would be to pay for a third party profiling tool such as JetBrains dotTrace; but I need to make sure that I've explored the free options first before going cap in hand to my manager.
views:
42answers:
1
A:
There is the CLR Profiler that lets you review various object graphs (I've never used it):
Of course, ANTS Profiler (free trial) is an often recommended profiler. You shouldn't need to manually garbage collect, the GC is a very intelligently built solution that will likely be more optimal than any manual calls you do. A better approach is to be minimalist with the number of objects you keep in memory - and be rid of memory-heavy objects as soon as possible if memory is priority.
Adam
2010-06-17 08:03:45
Thanks adam, I've just tried CLR Profiler both on my desktop machine and on a 64bit application server. It crashed in both circumstances for different reasons; both times profiling the same application. I've done a search on problem with CLR profiler and have found that there seems to be quite a few stability issues with it; so I won't waste any more time using it. I will take a look ANTS which looks quite powerful and also JetBrains dotTrace. Thanks for your imput
Shantaram
2010-06-17 10:15:08