zoukankan      html  css  js  c++  java
  • 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
    */

  • 相关阅读:
    《算法导论》读书笔记
    【原创】POI操作Excel导入导出工具类ExcelUtil
    10-JMM
    09-字节码执行引擎
    08-类加载机制
    07-前端编译与优化(待补充)
    06-字节码指令
    05-类文件结构
    04-垃圾回收(2)
    03-垃圾回收(1)
  • 原文地址:https://www.cnblogs.com/cutepig/p/1601165.html
Copyright © 2011-2022 走看看