DCSIMG
VMMap Allocation Profiling and Leak Detection - All Your Base Are Belong To Us

All Your Base Are Belong To Us

Mostly .NET internals and other kinds of gory details

VMMap Allocation Profiling and Leak Detection

We have already seen VMMap as a tool for inspecting memory utilization and the layout of a process’ virtual address space.

The latest VMMap version (rush to download!) ships with a memory allocation profiler for VirtualAlloc() and HeapAlloc() calls. Additionally, the tool can display the allocating call stack for every heap block.

Sounds interesting? Here’s how to use it. You launch VMMap, and instead of inspecting an existing process, you tell it to launch and trace another process. (It uses Microsoft Detours to hook allocation APIs and log the information.)

image

Now you exercise your leaking application. The Timeline window gives you a good understanding of what type of memory is leaking:

image

The orange areas here are heap allocations, which are growing while everything else is fairly steady. When you’re convinced that there’s a leak, go to the detail view and start clicking suspicious heap areas. The “Heap Allocations” button at the bottom of the screen will become enabled, and clicking it provides a summary of allocations:

image

And now for each allocation you can obtain the stack trace:

image

Another approach is to click the “Trace” button, sort the output by bytes allocated, and start looking for suspicious call stacks:

image

I hope VMMap will be as useful to you as it is to me—and with memory allocation profiling, twice as useful.

Comments

Ofek said:

I can't seem to get VMMap to use symbols for my own modules (BatteryMeter in your example above). I modified the symbol path dialog entry, and still no good. Did you succeed in viewing your own allocating function?

# April 24, 2012 11:33 AM

Sasha Goldshtein said:

@Ofek: Yep, it works for me. Is there any chance that you're using FPO or an FPO-enabled CRT?

# April 28, 2012 3:01 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: