One of the most frustrating challenges we have to deal with when we create an application is a memory related problem. These may actually manifest themselves as out of memory exceptions or possibly slow downs as the system waits for resources. Diagnosing the cause of these problems requires cunning and perseverance.

So how do you go about finding the offending piece of code when your application contains several layers and thousands of lines of code. The answer is to dig into your bag of wizard’s spells and exercise the demons to send them back to the beyond.

Ok, that is a little dramatic. The real answer is to get a profiling or analysis tool. There are several out there. Some are free. Of course the ones with all the bells and whistles will set you back the price of a few first person shooter games.

While I was doing some diagnosis recently I ended up working with Dev Partner’s Memory Analysis, Red Gate’s ANTS, as well as the CLR Profiler and DebugDiag from Microsoft. This is by no means a complete list of what is available, just what I have tried. They each have their strong points and aggravations.

Memory Analysis has a really nice real time graph of the memory being allocated system. This helps as you are stepping through code to tell you at what point you app becomes a pig. The problem is that it isn’t good at telling you which object is bellying up to the buffet.

For the detailed level and ease of reading I actually found that CLR Profiler did a nice job. The allocation graph gives you a tree diagram that is easy to follow and allows you to drill down when you find a point of interest.

In the end I found that this is a process that still takes a lot of basic troubleshooting skills. Changing your code to exercise different scenarios and building test apps to isolate suspected thieves are crucial tasks. I hope this little bit of information can help some of you out there if you run into this type of situation.