内存泄漏在0行代码中
Memory leaks in 0 rows of code.
查看此最简单的应用程序:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
void main(void)
{
_CrtDumpMemoryLeaks();
}
它在调试窗格中产生下一个输出:
Detected memory leaks!
Dumping objects ->
{94} normal block at 0x012EA298, 8 bytes long.
Data: <Dw > 44 77 D9 00 00 00 00 00
{93} normal block at 0x012F0DA8, 20 bytes long.
Data: < / / / > A8 0D 2F 01 A8 0D 2F 01 A8 0D 2F 01 01 01 CD CD
Object dump complete.
Detected memory leaks!
如何可能?
Win10,VS2015,目标平台版本10.0.14393.0
i"修复",然后使用下一个操作:
- 让
stdlib
在退出之前自行检查并显示内存泄漏_CRTSETDBGFLAG(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
- 要查看我在
exit.cpp:129
中放置的消息exitProcess(return_code);
结果代码:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
void main(void)
{
// Show memory leaks before exit
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
auto a = new int[33333];
//_CrtDumpMemoryLeaks(); // DO NOT USE
}
现在我只能看到我的记忆泄漏在调试窗格中!
Detected memory leaks!
Dumping objects ->
{95} normal block at 0x014B4F48, 133332 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
Object dump complete.
33333 * 4 = 133332。
感谢@jamesbean和MSDN文章"使用CRT库查找内存泄漏"
相关文章:
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 这行代码在C++类中意味着什么
- 理解这行C++指针代码
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 为什么我不能在同一代码行中创建和打开流?
- 这行代码到底是什么意思?
- Eulers 项目问题 no 345 听不懂几行代码
- 使用基于数组和范围的 For 循环替换一些基本代码行
- 添加新行时工作代码引发异常.调试技巧?
- 您好,我实际上想了解以下代码.有人可以详细说明代码它到底在做什么吗?为什么它会在第 31 行崩溃
- 我编写了以下代码来读取C++矩阵,然后打印其行和列.我收到此错误
- 这行代码中的内存是如何分配"int **v = new int*[n]; "的?
- 在 c++ 中逐行读取文件(将代码从 Python 转换为 C++)
- 在下面的C 代码的行中使用(n/8)和(n*7/8)的目的是什么?
- 获取在C++中实例化的TCL解释器中执行代码的行号
- C++代码中断行,为了我的爱,我无法修复它
- 如何知道两个 C++ 断点之间的代码汇编行的大小
- 为什么在 gcov 中声明"不包含代码"的行
- c++返回元素在没有代码的行上给出访问冲突