本帖最后由 worldy 于 2014-02-27 18:56:20 编辑

解决方案 »

  1.   

    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {521} normal block at 0x003995C0, 28 bytes long.
     Data: <   x            > 0C 00 E5 78 05 00 00 00 05 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {520} normal block at 0x00399550, 46 bytes long.
     Data: <   x            > 0C 00 E5 78 0E 00 00 00 0E 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {519} normal block at 0x003994E0, 48 bytes long.
     Data: <   x            > 0C 00 E5 78 0F 00 00 00 0F 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {518} normal block at 0x00399478, 42 bytes long.
     Data: <   x            > 0C 00 E5 78 0C 00 00 00 0C 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {517} normal block at 0x003985D8, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {516} normal block at 0x00398580, 28 bytes long.
     Data: <   x            > 0C 00 E5 78 05 00 00 00 05 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {515} normal block at 0x00398510, 50 bytes long.
     Data: <   x            > 0C 00 E5 78 10 00 00 00 10 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {514} normal block at 0x003984B8, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {513} normal block at 0x00398460, 24 bytes long.
     Data: <   x            > 0C 00 E5 78 03 00 00 00 03 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {512} normal block at 0x00398408, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {510} normal block at 0x00398FE0, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {509} normal block at 0x00398F88, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {508} normal block at 0x00398F20, 40 bytes long.
     Data: <   x            > 0C 00 E5 78 0B 00 00 00 0B 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {507} normal block at 0x00398EC8, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {506} normal block at 0x00398E60, 44 bytes long.
     Data: <   x            > 0C 00 E5 78 0D 00 00 00 0D 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {505} normal block at 0x00398DF8, 38 bytes long.
     Data: <   x            > 0C 00 E5 78 0A 00 00 00 0A 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {504} normal block at 0x00398DA0, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {503} normal block at 0x00398D48, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {502} normal block at 0x00398CE0, 38 bytes long.
     Data: <   x            > 0C 00 E5 78 0A 00 00 00 0A 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {501} normal block at 0x00398C88, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {500} normal block at 0x00398C30, 24 bytes long.
     Data: <   x            > 0C 00 E5 78 03 00 00 00 03 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {499} normal block at 0x00398BD8, 24 bytes long.
     Data: <   x            > 0C 00 E5 78 03 00 00 00 03 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {498} normal block at 0x00398B78, 36 bytes long.
     Data: <   x            > 0C 00 E5 78 09 00 00 00 09 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {497} normal block at 0x00398B20, 24 bytes long.
     Data: <   x            > 0C 00 E5 78 03 00 00 00 03 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {496} normal block at 0x00398AC8, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {495} normal block at 0x00398A70, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {494} normal block at 0x00398A18, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {493} normal block at 0x003989C0, 24 bytes long.
     Data: <   x            > 0C 00 E5 78 03 00 00 00 03 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {492} normal block at 0x00398968, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {491} normal block at 0x00398910, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {490} normal block at 0x003988B8, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {489} normal block at 0x00398860, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {488} normal block at 0x003987E8, 60 bytes long.
     Data: <   x            > 0C 00 E5 78 15 00 00 00 15 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {487} normal block at 0x00398778, 46 bytes long.
     Data: <   x            > 0C 00 E5 78 0E 00 00 00 0E 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {486} normal block at 0x00398710, 42 bytes long.
     Data: <   x            > 0C 00 E5 78 0C 00 00 00 0C 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {485} normal block at 0x00393448, 28 bytes long.
     Data: <   x            > 0C 00 E5 78 05 00 00 00 05 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {484} normal block at 0x003986B0, 32 bytes long.
     Data: <   x            > 0C 00 E5 78 07 00 00 00 07 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {483} normal block at 0x00398648, 44 bytes long.
     Data: <   x            > 0C 00 E5 78 0D 00 00 00 0D 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {482} normal block at 0x003933D8, 50 bytes long.
     Data: <   x            > 0C 00 E5 78 10 00 00 00 10 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {481} normal block at 0x00393360, 60 bytes long.
     Data: <   x            > 0C 00 E5 78 15 00 00 00 15 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {480} normal block at 0x00393BB0, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {479} normal block at 0x00393B58, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {477} normal block at 0x00393AE8, 48 bytes long.
     Data: <   x            > 0C 00 E5 78 0F 00 00 00 0F 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {476} normal block at 0x00393A90, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {78} normal block at 0x00393998, 32 bytes long.
     Data: <   x            > 0C 00 E5 78 07 00 00 00 07 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {77} normal block at 0x00393940, 28 bytes long.
     Data: <   x            > 0C 00 E5 78 05 00 00 00 05 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {76} normal block at 0x003938D8, 44 bytes long.
     Data: <   x            > 0C 00 E5 78 0D 00 00 00 0D 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {75} normal block at 0x00393878, 34 bytes long.
     Data: <   x            > 0C 00 E5 78 08 00 00 00 08 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {74} normal block at 0x00393818, 30 bytes long.
     Data: <   x            > 0C 00 E5 78 06 00 00 00 06 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {73} normal block at 0x003937C0, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {72} normal block at 0x00393748, 56 bytes long.
     Data: <   x            > 0C 00 E5 78 13 00 00 00 13 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {71} normal block at 0x003936F0, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {70} normal block at 0x00393680, 48 bytes long.
     Data: <   x            > 0C 00 E5 78 0F 00 00 00 0F 00 00 00 01 00 00 00 
      

  2.   

    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {69} normal block at 0x00393628, 28 bytes long.
     Data: <   x            > 0C 00 E5 78 05 00 00 00 05 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {68} normal block at 0x003935D0, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {67} normal block at 0x00393578, 28 bytes long.
     Data: <   x            > 0C 00 E5 78 05 00 00 00 05 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {66} normal block at 0x00393500, 54 bytes long.
     Data: <   x            > 0C 00 E5 78 12 00 00 00 12 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {65} normal block at 0x003934A0, 34 bytes long.
     Data: <   x            > 0C 00 E5 78 08 00 00 00 08 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {64} normal block at 0x00395D10, 22 bytes long.
     Data: <   x            > 0C 00 E5 78 02 00 00 00 02 00 00 00 01 00 00 00 
    f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {63} normal block at 0x00395CB0, 36 bytes long.
     Data: <   x            > 0C 00 E5 78 09 00 00 00 09 00 00 00 01 00 00 00 
    Object dump complete.
    线程 'Win32 线程' (0xd6c) 已退出,返回值为 0 (0x0)。
    线程 'Win32 线程' (0x1210) 已退出,返回值为 0 (0x0)。
    线程 'Win32 线程' (0x1e88) 已退出,返回值为 0 (0x0)。
    程序“[1560] Test2.exe: 本机”已退出,返回值为 0 (0x0)。---------------居然如此之多的泄漏,大家发表发表高见啊
      

  3.   

    c++ 类的构造应该是先构造父类,再构造子类
    析构相反,把析构函数改为virtural 试试
      

  4.   


    除了~CTest2App(){ _CrtDumpMemoryLeaks();}外,都是向导生成的,没有自己写的代码啊
      

  5.   

    我的意思是指app 子类析构了,他的父类部分还没析构,如果不是virtual 的话?
      

  6.   


    刚刚试过,加上virtual还是一样多的泄漏,方便的话,你可以可以试一下
      

  7.   


    刚试过一种方案:创建一个空类clsTest,在其释构函数中执行泄漏检测;定义一个clsTest全局变量tt,让其释构函数在app的释构函数执行完毕之后执行,其结果还是一样,还是有那么多的泄漏
      

  8.   

    检测的位置有问题,解析的时候theApp本身还是存在的,而且由C环境构造的很多全局变量没有被释放
      

  9.   

    昨晚没有环境没有替你试!
    今天看了msdn,他有解释
    在某些情况下, _CrtDumpMemoryLeaks 可能给出错误的内存泄漏指示。 如果使用将内部分配标记为 _NORMAL_BLOCK 而不是 _CRT_BLOCK 或 _CLIENT_BLOCK 的库,则可能发生这种情况。 在这种情况下, _CrtDumpMemoryLeaks 无法区分用户分配和内部库分配。 如果在 _CrtDumpMemoryLeaks 调用点之后运行库分配的全局析构函数,则每个内部库分配都会报告为内存泄漏。
    如果要解决这个情况
    如果应用程序有多个退出点,并不需要在每个退出点都手动设置一个对 _CrtDumpMemoryLeaks 的调用。 应用程序开头部分对 _CrtSetDbgFlag 的调用会导致在每个退出点自动调用 _CrtDumpMemoryLeaks。 您必须设置两个位域,如下所示:以带有颜色区分的格式查看复制到剪贴板_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    通过设置 _CrtSetDbgFlag方式可以避免这种情况
      

  10.   

    CMFCApplication6App::CMFCApplication6App()
    {
    int* a= new int[256];
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );这里的a 我故意没有释放
    我没有调用_CrtDumpMemoryLeaks,在退出也报内存泄露,如果释放那个a ,退出不报泄露
      

  11.   


    这个我知道,其实如果  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );不设置,_CrtDumpMemoryLeaks();也不调用,也会报告(根据msdn,设置_CRTDBG_LEAK_CHECK_DF 后,在退出点会自动调用_CrtDumpMemoryLeaks)看来情况确实如8#10#所说的,theApp释放之后,内部环境还有很多东东没有释放,因此用户调用_CrtDumpMemoryLeaks是多余的,也是不可以控制的
      

  12.   

    这个我知道,其实如果  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );不设置,_CrtDumpMemoryLeaks();也不调用,也会报告(根据msdn,设置_CRTDBG_LEAK_CHECK_DF 后,在退出点会自动调用_CrtDumpMemoryLeaks)看来情况确实如8#10#所说的,theApp释放之后,内部环境还有很多东东没有释放,因此用户调用_CrtDumpMemoryLeaks是多余的,也是不可以控制的
    如果知道就能推测出app析构后,还有东西没有被释放!