For debugging purposes, when I'm writing an app, the first thing I do is put the following into the stdafx.h:
// -- leak detection ----------------------------------------------------------
#ifdef _DEBUG
// http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=VS.80).aspx
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
Then I add the following to the beginning of the program's main() function:
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
//_CrtSetBreakAlloc( 670 );
#endif
Redefining the new operator to give leak information is a useful tool. But what about CoTaskMemAlloc and CoTaskMemFree ? How can I detect leaks using these?
I'm writing software that uses COM and DirectShow and need to know how to trace leaks caused by using CoTask allocations.
thanks!