add memory leak detection
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@475 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
de2a6e513d
commit
2287a53487
1 changed files with 35 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// The Loki Library
|
||||
// Copyright (c) 2006 Peter Kmmel
|
||||
// Copyright (c) 2006 Peter Kümmel
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
|
@ -136,8 +136,42 @@ void D::foo()
|
|||
/////////////////////////////////////////
|
||||
void test_more();
|
||||
|
||||
//#define MSVC_DETECT_MEMORY_LEAKS
|
||||
#ifdef MSVC_DETECT_MEMORY_LEAKS
|
||||
|
||||
#include <crtdbg.h>
|
||||
#include <cassert>
|
||||
|
||||
void heap_debug()
|
||||
{
|
||||
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
|
||||
|
||||
// Turn on leak-checking bit
|
||||
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
|
||||
|
||||
//tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
|
||||
|
||||
// Turn off CRT block checking bit
|
||||
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
|
||||
|
||||
// Set flag to the new value
|
||||
_CrtSetDbgFlag( tmpFlag );
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void heap_debug()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
heap_debug();
|
||||
|
||||
A* a = new A;
|
||||
B* b = new B;
|
||||
|
|
Loading…
Reference in a new issue