// compile with: cl testMemLeak.cpp -D_DEBUG /MTd -Od -Zi -W3 /link -verbose:lib /debug
/*
* This program concentrates on allocating and freeing memory
* blocks to test the functionality of the _crtDbgFlag flag..
*/
/*
* The memory leakage info is output by OutputDebugString, which can be catched by DebugView
*
*/
// the 1st 3 line MUST put top most
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <vector>
#include <windows.h>
#ifdef _DEBUG
//#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
#endif
inline void EnableMemLeakCheck()
{
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
}
void main()
{
EnableMemLeakCheck();
//int* leak = new int[10];
//malloc_(100);
//_malloc_dbg(100, _NORMAL_BLOCK, __FILE__, __LINE__);
std::vector<int> v(10);
v.resize(1);
v.reserve(100);
}
/*
Modify xmemory
void deallocate(pointer _Ptr, size_type)
{ // deallocate object at _Ptr, ignore size
operator delete(_Ptr);
}
to test memory leakage in STL
*/