MFC诊断问题

时间:2009-12-06 20:01:44

标签: mfc memory-leaks

所以我放弃了实现自己的memoryleak跟踪(在这个问题overloading new and delete中)并尝试使用MFC函数来识别我的内存泄漏。 所以我完全按照这里描述的那样做:

http://msdn.microsoft.com/en-us/library/8ky2wh64(VS.80).aspx

这是我的代码:

#ifdef _DEBUG
    CMemoryState oldMemState, newMemState, diffMemState;
    oldMemState.Checkpoint();
#endif

    int* test = new int;

#ifdef _DEBUG
    newMemState.Checkpoint();
    if( diffMemState.Difference( oldMemState, newMemState ) )
    {
        TRACE( "Memory leaked!\n" );
        diffMemState.DumpStatistics();
        diffMemState.DumpAllObjectsSince();
    }
#endif

但输出显示

,而不是输出任何有用的信息
    Memory leaked!
        0 bytes in 0 Free Blocks.
        4 bytes in 1 Normal Blocks.
        0 bytes in 0 CRT Blocks.
        0 bytes in 0 Ignore Blocks.
        0 bytes in 0 Client Blocks.
        Largest number used: 0 bytes.
        Total allocations: 4 bytes.
        Dumping objects ->
    {714538} normal block at 0x029628C8, 4 bytes long.
Data: <    > CD CD CD CD 
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp(306) : {714536} client block at 0x022F6040, subtype c0, 68 bytes long.
  a CWinThread object at $022F6040, 68 bytes long
    {714535} normal block at 0x03B607A8, 4 bytes long.
Data: <@`/ > 40 60 2F 02 
    {714534} normal block at 0x03B58C70, 8 bytes long.
Data: < N      > F0 4E B5 03 00 00 00 00 
    {714533} client block at 0x03B54EF0, subtype c0, 12 bytes long.
    a CEvent object at $03B54EF0, 12 bytes long
    {714524} normal block at 0x022FFFC8, 1 bytes long.
Data: < > CD 
    {714523} normal block at 0x03B608C0, 12 bytes long.
Data: <    x   h   > E8 07 B6 03 78 08 B6 03 68 97 9A 02 
    {714522} normal block at 0x03B60878, 12 bytes long.
Data: <    0   P   > C0 08 B6 03 30 08 B6 03 50 82 9A 02 
    {714521} normal block at 0x03B60830, 12 bytes long.
Data: <x           > 78 08 B6 03 E8 07 B6 03 88 81 9A 02 
    {714520} normal block at 0x03B607E8, 12 bytes long.
Data: <0           > 30 08 B6 03 C0 08 B6 03 CD CD CD CD 
    {714515} normal block at 0x03B606B0, 104 bytes long.
Data: <                > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD 
    {714510} normal block at 0x03B60668, 12 bytes long.
Data: <            > C8 03 B6 03 20 06 B6 03 88 AC 9A 02 
    {714509} normal block at 0x03B60620, 12 bytes long.
Data: <h       h   > 68 06 B6 03 D8 05 B6 03 68 97 9A 02 

.........这就是这样,一直在进行,括号中的数字正在倒计时(实际上从来没有耐心等待让它倒数到1)

总是从这个高714538开始 那么 - 我做错了什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

here开始,它表明应该在你调用Checkpoint()的CMemoryState对象上调用DumpAllObjectsSince()。

所以你的代码应该是:

    {
            TRACE( "Memory leaked!\n" );
            diffMemState.DumpStatistics();
            //diffMemState.DumpAllObjectsSince();
            oldMemState.DumpAllObjectsSince();
    }
相关问题