Memory leak detection in C ++ / windows

For debugging purposes, when I write the application, the first thing I do is put in 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 will add the following to the beginning of the main () function of the program:

#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
//_CrtSetBreakAlloc( 670 );
#endif  

Revising a new operator to provide leak information is a useful tool. But what about CoTaskMemAlloc and CoTaskMemFree? How can I detect leaks using these?

I am writing software using COM and DirectShow, and you need to know how to track leaks caused by using CoTask distributions.

thank!

+3
source share
4 answers

- , .

+3

, . Embrace RAII , , .

, ( , FTM). delete .

+6
+1

CoTaskMemAlloc CoTaskMemFree? ?

, malloc/free . , .

, , . , / /.

: CoTaskMemAlloc?

0

Source: https://habr.com/ru/post/1759646/


All Articles