Tuesday, June 5, 2012

Quality: Tracking Down Memory Usage With Application Verifier, TruScan, and UMDH

This post is about how to drive up code quality specifically relating to memory usage.  These are things you should consider doing before you ship your code even if you feel like your code's memory usage is where it should be.  I will be talking about three tools here: Appverif, TruScan, affiliated with TTT (Time Travel Tracing aka iDNA), and UMDH.

Step 1: Enable Application Verifier on your code and attach Windbg to the process!  Get it here.  I think I may have said this a million times in this blog, but it will find almost all common C/C++ type defects, not just leaks.  This should be part of your normal workflow.  Period.  Always validate significant changes with appverif.  If you have this part of day to day development workflow, then you will not miss most defects.  If you are writing drivers, there is also Driver Verifier.

Step 2: Use TruScan.  TruScan utilizes TTT to keep track of all of your allocations.  It knows, correctly most of the time, when there are no more references to allocated memory and the memory is leaked.  It kind of takes a while, so this is something good to do like at a end of a milestone and you feel your code is mostly stable.

Step 3: User Mode Heap Dump (umhd.exe) is where you go next when all leaks are eradicated.  Your typical working set is not where you would like it to be, so you can use UMHD to help you profile your code to see what stacks are the biggest memory hogs.  After you identify these code paths, you should rationalize whether or not the memory usage was worth the cost, or maybe you were doing something dumb that should be changed.

Actually, there is a Step 0.

Step 0: Architect and design your code to be high performance and efficient to begin with.  Yes, the Analysis of Algorithms course you take in your CS program really is important.  Common sense often also applies here.

I didn't go into details on how to use these tools.  I figured you should be able to find them on the web, and their documentation should get you off the ground.  Feel free to give some feed back if you want more instructions on these tools.


  1. Hi Sam,

    Where the heck do I find this TruScan? I've done a bit of Googling, and I find it mentioned a bit, but no page I can find suggests where to get it.


  2. I am not sure...maybe part of one of the Windows SDKs?