Memory leakage

// 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
/

Powered by Jekyll and Theme by solid

本站总访问量