Originally posted by: Tim Askey
#ifdef _DEBUG
//forward fn. decl.
//set various sys hooks
LONG g_lFirstReqCaught = 0;
BOOL AFXAPI AllocHook(size_t nSize, BOOL bObject, LONG lRequestNumber)
//turn off memory alloc tracking
//set memory allocation breakpoints here
This installs a debug hook that lets you catch allocations.
If you are having trouble catching memory allocation try using the code below:
#pragma warning(disable : 4074)
#pragma init_seg(compiler)
BOOL AFXAPI AllocHook(size_t nSize, BOOL bObject, LONG lRequestNumber);
static AFX_ALLOC_HOOK PrevAllocHook = AfxSetAllocHook(AllocHook);
{
if(!g_lFirstReqCaught)
{
g_lFirstReqCaught = lRequestNumber;
TRACE("L_Afx: Caught first alloc request number {%d}\n", g_lFirstReqCaught);
PrevAllocHook = AfxSetAllocHook(PrevAllocHook);
}
return TRUE;
}
#endif
By using it you can install breakpoints so long as the allocation number is >= g_lFirstReqCaught.
Originally posted by: Eric Forget
Just add this at the top off all your none MFC .cpp files:
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
This will show you the line and file name where the not deallocated memory is allocated! (in the output of the debuger)...
PS: It work in VC 5 but i have some problems to make it work in VC 6... (if you found a solution for make it work in VC 6 tell me please...)
Eric
Reply