views:

201

answers:

5
  1. There is a memory leak in my application. The memory consumption shoots up after a couple of days of running the application. I need to dump call stack information of each orphaned block address. How is it possible with WinDbg?

  2. I tried referring to document created by my colleague, but I'm confused about how to specify the symbol path and stuff like that. It didn't work out. Where can I get a step-by-step document.

A: 
  1. See the "Who called HeapAlloc" entry on this page: http://www.windbg.info/doc/1-common-cmds.html

  2. See this page: http://www.microsoft.com/whdc/DevTools/Debugging/debugstart.mspx for info about the symbol server.

Moishe
+2  A: 

You can use umdh.exe to capture and compare snapshots of the process before and after leak happens. This works best with Debug binaries - it will give you the callstacks of memory allocated between the 1st and the 2nd snapshot.

http://support.microsoft.com/kb/268343

Steve Townsend
+1 UMDH is an excellent tool for tracking down leaks. Be sure to take several snapshots and compare so you can see the growth. Though not necessary, it helps a lot to have symbols locally rather than using a symbol server as the local pdbs will load much much quicker.
nithins
@nithins - thanks for the extra info in your comment
Steve Townsend
A: 

First of all I must say you must be a masochist to use WinDbg! If you code in C++ you are not developing drivers, even in this case there are more decent debuggers. Throw away that crap, really!

To tackle the problem I would first use a static code checker to analyze the code. PC-Lint is a cheap one. Then run the app inside a dynamic code checker (like Boundschecker for example or Purify).

Only if you could not find the culprit code, I would start where you are. Investing in such a tool is really worth the money if you write apps that have to run for days and days. It enables you a faster validation (not 100%) of the code before you start long running tests to find out what a code checker would have found within minutes...

With Boundchecker you can use Marks, it is using a similar feature (or maybe exactly the same?) than Steve Townsend is telling about. With it you would see all memory blocks still hanging on in memory since the last Mark. This is rather tedious in big apps as you end up with a big buck of memory blocks.... But if you came up with that question, then you probably are already so desperate that you would like to try it ;-)

jdehaan
A: 

I had never used Memory Validator (http://www.softwareverify.com/cpp/memory/index.html) before yesterday but it did help me track something down today.

Joe
A: 

For leaks I have been using Visual Leak Detector while it only works in debug mode it is free and seems reasonably reliable

Harald Scheirich