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.)
Now you exercise your leaking application. The Timeline window gives you a good understanding of what type of memory is leaking:
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:
And now for each allocation you can obtain the stack trace:
Another approach is to click the “Trace” button, sort the output by bytes allocated, and start looking for suspicious call stacks:
I hope VMMap will be as useful to you as it is to me—and with memory allocation profiling, twice as useful.