Click here to Skip to main content
15,898,768 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Getting version information into a DLL using manually created .rc file Pin
Iain Clarke, Warrior Programmer19-Jun-07 6:27
Iain Clarke, Warrior Programmer19-Jun-07 6:27 
GeneralRe: Getting version information into a DLL using manually created .rc file Pin
Barry True19-Jun-07 8:48
Barry True19-Jun-07 8:48 
GeneralRe: Getting version information into a DLL using manually created .rc file Pin
Iain Clarke, Warrior Programmer19-Jun-07 10:59
Iain Clarke, Warrior Programmer19-Jun-07 10:59 
QuestionDebug to detect Memory Leak Pin
krishnakumar7519-Jun-07 5:09
krishnakumar7519-Jun-07 5:09 
QuestionRe: Debug to detect Memory Leak Pin
Mark Salsbery19-Jun-07 6:39
Mark Salsbery19-Jun-07 6:39 
AnswerRe: Debug to detect Memory Leak Pin
krishnakumar7520-Jun-07 5:20
krishnakumar7520-Jun-07 5:20 
GeneralRe: Debug to detect Memory Leak Pin
Mark Salsbery20-Jun-07 7:31
Mark Salsbery20-Jun-07 7:31 
GeneralRe: Debug to detect Memory Leak Pin
Mark Salsbery20-Jun-07 8:05
Mark Salsbery20-Jun-07 8:05 
krishnakumar75 wrote:
I used _CRTDBG_MAP_ALLOC and _CrtMemState() to set set points in various location of application and compared to find the leak. Sometime it alerts for memory leaks and sometimes not.


Where you do checkpoints can effect the results. You need to make sure no allocations that
aren't freed are made between checkpoints.

I prefer to use a static class object so I can catch all leaks (except possibly any in other
static objects) that occur over the lifetime of the app.

I use this in one (usually the main) source module:
#ifdef _DEBUG
class _MemStateCheck
{
public:
   CMemoryState oldMemState, newMemState, diffMemState;
 
   _MemStateCheck();
   ~_MemStateCheck();
};

_MemStateCheck::_MemStateCheck()
{
   oldMemState.Checkpoint();
}
 
_MemStateCheck::~_MemStateCheck()
{
    newMemState.Checkpoint();
    if( diffMemState.Difference( oldMemState, newMemState ) )
    {
        TRACE( "************************\n" );
        TRACE( "Memory leaks Detected\n" );
        TRACE( "************************\n" );
        diffMemState.DumpStatistics();
        diffMemState.DumpAllObjectsSince();
    }
    else
    {
        TRACE( "************************\n" );
        TRACE( "No memory leaks Detected\n" );
        TRACE( "************************\n" );
    }
}
 
_MemStateCheck MemCheckObj;
#endif  //#ifdef _DEBUG

For MFC apps, I include this at the top of every source (cpp) file (under any #include lines):
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

To get file/line numbers for malloc, you should use _malloc_dbg instead of malloc (it will use the regular malloc in non-debug builds):
// Allocate 128 bytes
//void *p = malloc(128);
void *p = _malloc_dbg(128, _NORMAL_BLOCK, __FILE__, __LINE__ );





"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

GeneralRe: Debug to detect Memory Leak Pin
Mark Salsbery20-Jun-07 8:12
Mark Salsbery20-Jun-07 8:12 
QuestionKeystrokes for custom control in dialog Pin
kylur19-Jun-07 3:45
kylur19-Jun-07 3:45 
AnswerRe: Keystrokes for custom control in dialog Pin
Iain Clarke, Warrior Programmer19-Jun-07 4:04
Iain Clarke, Warrior Programmer19-Jun-07 4:04 
GeneralRe: Keystrokes for custom control in dialog Pin
kylur19-Jun-07 5:34
kylur19-Jun-07 5:34 
QuestionDB Date Pin
Try19-Jun-07 3:34
Try19-Jun-07 3:34 
Question_declspec and uuid [modified] Pin
Stephen Caldwell19-Jun-07 3:31
Stephen Caldwell19-Jun-07 3:31 
AnswerRe: _declspec and uuid Pin
Matthew Faithfull19-Jun-07 4:33
Matthew Faithfull19-Jun-07 4:33 
GeneralRe: _declspec and uuid Pin
Stephen Caldwell19-Jun-07 5:11
Stephen Caldwell19-Jun-07 5:11 
GeneralRe: _declspec and uuid Pin
Roger Stoltz19-Jun-07 5:12
Roger Stoltz19-Jun-07 5:12 
QuestionProblem with creating richeditctrl? Pin
Banks K19-Jun-07 3:05
Banks K19-Jun-07 3:05 
AnswerRe: Problem with creating richeditctrl? Pin
Rolando Cruz19-Jun-07 3:29
Rolando Cruz19-Jun-07 3:29 
GeneralRe: Problem with creating richeditctrl? Pin
Banks K19-Jun-07 3:36
Banks K19-Jun-07 3:36 
GeneralRe: Problem with creating richeditctrl? Pin
Rolando Cruz19-Jun-07 3:51
Rolando Cruz19-Jun-07 3:51 
QuestionFile reading problem Pin
Y_Kaushik19-Jun-07 3:05
Y_Kaushik19-Jun-07 3:05 
AnswerRe: File reading problem Pin
Rolando Cruz19-Jun-07 3:38
Rolando Cruz19-Jun-07 3:38 
AnswerRe: File reading problem Pin
Iain Clarke, Warrior Programmer19-Jun-07 4:08
Iain Clarke, Warrior Programmer19-Jun-07 4:08 
QuestionCOM/DCOM is now what? Pin
Rolando Cruz19-Jun-07 2:11
Rolando Cruz19-Jun-07 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.