.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Technology News >> General >> Post New Resource Bookmark and Share   

 Subscribe to Tech News

Detecting Memory leak in Visual Studio (Debug mode)

Posted By:elizas       Posted Date: May 04, 2010    Points: 10    Category: General    URL: http://www.dotnetspark.com  
 

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;
}

 Subscribe to Tech News


Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More Technology News Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend