Breaking on a memory allocation

I keep forgetting to write this down, so it's going on the good ole weblog for searching later.

If you have your code setup to do heap allocation tracking, _CTRDBG_LEAK_CHECK_DF and you'd like to break on a specific allocation, here's what you do once you've started debugging.

Add the following to the watch window.


Set the value to the allocation you'd like to break on. Now, if you're using the multi-threaded DLL runtime you'll have to provide a better context to the debugger. Like this.


So, if I'd like to see who allocated a hunk of memory, they were the 1000th caller, and they didn't free said memory, set the value to 1000, and the debugger will stop on allocation 1000.

Handy, big time handy.

Article on MSDN with more details, How to: Set Breakpoints on a Memory Allocation Number.

Labels: , , , , , ,

About this entry