Detecting memory leaks in VC++

One of the simplest ways to detect a leak in your code would be to use debugCRT.
Simple usage:
a. Create you project in visual studio
b. run the project in debug mode, then only you will find the memory leak dumps
int main()
{
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF);
//below call will break where the leak is in the code provided you give the error number as shown in the //dump.
_CrtSetBreakAlloc(108);
// your code here
//Below windows API will dump the leaks
_CrtDumpMemoryLeaks();
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *