_CRTDBG_MAP_ALLOC不显示文件名 [英] _CRTDBG_MAP_ALLOC not showing file name

查看:702
本文介绍了_CRTDBG_MAP_ALLOC不显示文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测内存泄漏,我使用make _CRTDBG_MAP_ALLOC宏来定位泄漏区域。所以我定义MACRO如下:

I am trying to detect memory leak, and I am using make _CRTDBG_MAP_ALLOC macro to locate where the leaks area. So I am defining MACRO like following:

#ifdef _DEBUG
    #define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
    #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
    #define new DEBUG_NEW
#endif

在我的代码中,我有:

UINT SomeFunThread( LPVOID pParam )
{
   _CrtMemState crtMemStateStart;
    _CrtMemState crtMemStateFinish;

    _CrtMemCheckpoint(&crtMemStateStart);


    // My suspisious code


     _CrtMemCheckpoint(&crtMemStateFinish);

      int nDifference(0);
      _CrtMemState crtMemStateDifference;
      nDifference = _CrtMemDifference(&crtMemStateDifference, &crtMemStateStart, &crtMemStateFinish);

    if(nDifference > 0)
        _CrtDumpMemoryLeaks();

    return 0;
}

(感谢Tushar Jadhav:内存消耗快速增加,然后下降很慢;内存泄漏

(Thanks to Tushar Jadhav: Memory consumption increases quickly, then drops very slowly; memory leak?)

但输出显示如下:

Detected memory leaks!
Dumping objects ->
{124058} normal block at 0x0000000031DED080, 24 bytes long.
 Data: < 0      ` $     > C8 30 F7 EF FE 07 00 00 60 D2 24 1D 00 00 00 00 

Detected memory leaks!
Dumping objects ->
C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18} 
normal block at 0x00780E80, 64 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.

那么我该如何显示文件名和泄漏位置?

So how can I make this show the file name and location of the leak?

推荐答案

似乎只有在该cpp文件中打开CRT时才显示泄漏行。

It seems the line of the leak only is displayed if the CRT is turned on in that cpp file.

这篇关于_CRTDBG_MAP_ALLOC不显示文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆