-
March 12th, 2013, 01:52 PM
#1
Where should I put _CrtDumpMemoryLeaks in the code?
To enable memory leaks detection, where should I put _CrtDumpMemoryLeaks in the code? For example, in the program I define a class A. A member function Load is defined in class A. The function Load is used to allocate memory for some variables in the heap and then at the end of pragram, the momory is deallocated in the destructor of class A. In this scenario, where should I put _CrtDumpMemoryLeaks in the code? Thanks.
-
March 12th, 2013, 02:28 PM
#2
Re: Where should I put _CrtDumpMemoryLeaks in the code?
How about looking in msdn first before posting to CG?
http://msdn.microsoft.com/en-us/libr...=VS.80%29.aspx
see the sample project listed in the link above
http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx
look at sample code, see where the sample puts the _CrtDumpMemoryLeaks calls.
-
March 12th, 2013, 03:32 PM
#3
Re: Where should I put _CrtDumpMemoryLeaks in the code?
You can also add
Code:
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
to a header that's included everywhere (stdafx.h perhaps) and
Code:
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
as early as possible in every cpp-file and in main
Code:
int main()
{
#if defined(_DEBUG)
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
tmpFlag |= _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF; // Check heap alloc and dump mem leaks at exit
_CrtSetDbgFlag( tmpFlag );
assert( !errno );
//_crtBreakAlloc = 58652; // Set to break on allocation number in case you get a leak without a line number
#endif
...
This will make every single leak to be detected regardless where it occur
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|