From: eliza on
The memory leak information is printed on "Output" window.
[ This advantage is in "Debug" mode only. ]
Example

int _tmain()
{
int* ptr = NULL;

ptr = (int*)malloc(sizeof(int)*20);

for( int i=0; i<20; ++i )
ptr[i] = i;

#ifndef NDEBUG

int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // Get current flag

flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit

_CrtSetDbgFlag(flag); // Set flag to the new value

#endif

//free(ptr);

printf("\n\nPress Enter...");
getch();
return 0;
}

http://www.mindfiresolutions.com/Detecting-Memory-leak-in-Visual-Studio-Debug-mode-749.php



Anwar Khan wrote:

Finding Memory Leaks
26-Apr-10

Hi all,

I have a MFC/C++ Application developed. I see a lot of Memory Leaks Dump in
the Visual Studio output window when run the app via the debugger.

My application consists of an exe, and a few DLLs. The DLLs are loaded by
the exe using LoadLibrary.

And any memory leaks are in any of the DLLs, there is no info like where in
the sourcecode (file name and line number) where the leak was caused. All
that I see is the number of bytes of leaked.
Whereas, any leak in the EXE shows exact info about file name and line
number.

Any help/tips/suggestions to help me solve the memory leaks would be highly
appreciated.

Thanks.
Anwar.

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
BOOK REVIEW: Effective C#, Second Edition [Addison Wesley]
http://www.eggheadcafe.com/tutorials/aspnet/b2f8766d-a4c1-4d5a-97af-c38852b3b455/book-review-effective-c.aspx