Visual Studio内存泄漏检测未打印文件名和行号 [英] Visual Studio memory leak detection not printing file name and line number
问题描述
我想检查程序是否存在内存泄漏,并找到此Microsoft文章.
I want to check my program for memory leaks and found this Microsoft article.
我完全关注了这篇文章并添加了
I thoroughly followed the article and added
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
和
_CrtDumpMemoryLeaks();
程序退出时.
它可以正确地将所有内存泄漏信息转储到我的输出窗口中,但这是问题所在:
It properly dumps all the memory leak info in my output window, but here's the problem:
它不会显示内存泄漏所在的文件名和行号!
在文章中说,使用#define _CRTDBG_MAP_ALLOC
可以打印文件名和行号,但不适用于我.
It says in the article that with #define _CRTDBG_MAP_ALLOC
it prints the file name and line number, but it doesn't for me.
我的输出看起来像这样
Detected memory leaks!
Dumping objects ->
{3456} normal block at 0x038F81E8, 560 bytes long.
Data: < A B> 00 00 00 00 00 00 10 41 00 00 00 FF 00 00 E6 42
{3447} normal block at 0x038F8170, 56 bytes long.
Data: < B ^ B > 80 42 90 03 10 02 5E 08 80 42 90 03 00 00 CD CD
{3440} normal block at 0x038F86B0, 840 bytes long.
Data: < A B> 00 00 00 00 00 00 10 41 00 00 00 FF 00 00 A8 42
...
所以我不能真正使用它...也按F4转到该行不起作用.
So I can't really work with that... also pressing F4 to go to the line doesn't work.
能请你帮我吗?
推荐答案
我希望这对您有帮助,如果您尚未弄清楚@ A.D是否适用于Win32应用程序,我们需要重写新的运算符.不幸的是,它不适用于MFC应用程序.:(
I hope this helps if u havent figured out @A.D, works for win32 applications, we need to override the new operator. unfortunately it doesnot work for MFC application.:(
#define _CRTDBG_MAP_ALLOC
#include<iostream>
#include <crtdbg.h>
#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
int main()
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ) ;
char *a = new char[10];
return 0;
}
这篇关于Visual Studio内存泄漏检测未打印文件名和行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!