I am using the instructions found here to try to find memory leaks in a Win32 application. As described, I put the
#define _CRTDBG_MAP_ALLOC
#include
Given a list of leaks at the end of the run, something like:
Detected memory leaks!
Dumping objects ->
{12913} normal block at 0x000002BC648BB9D0, 82 bytes long.
Data: 68 00 74 00 74 00 70 00 3A 00 2F 00 2F 00 61 00
{12912} normal block at 0x000002BC648B8030, 24 bytes long.
Data: <0 d ` > 30 CD 89 64 BC 02 00 00 D8 02 60 E5 F7 7F 00 00
...
It is easy to find where these memory blocks were allocated using _CrtSetBreakAlloc
for example for stop when allocation with allocation number 12913
happens one has to put
...
_CrtSetBreakAlloc(12913);
...
somewhere in code before the allocation happens: beginning of the unit tests or main-function are some possible examples. Now, void* __CRTDECL operator new(size_t const size)
will throw an exception when block with allocation number 12913
is allocated and from the call-stack in debugger it is easy to find where the allocation did happen.