首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MFC诊断问题

MFC诊断问题
EN

Stack Overflow用户
提问于 2009-12-07 04:01:44
回答 1查看 1.6K关注 0票数 2

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

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

这是我的代码:

代码语言:javascript
复制
#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

但是,输出并没有输出任何有用的信息,而是显示

代码语言:javascript
复制
    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这个高数字开始,所以-我做错了什么?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-12-07 05:48:54

here中,它显示应该在调用了Checkpoint()的CMemoryState对象上调用DumpAllObjectsSince()。

所以你的代码应该是:

代码语言:javascript
复制
    {
            TRACE( "Memory leaked!\n" );
            diffMemState.DumpStatistics();
            //diffMemState.DumpAllObjectsSince();
            oldMemState.DumpAllObjectsSince();
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1856430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档