C++ 在一个非常简单的程序中检测到内存泄漏。怎么办?
我的大程序内存泄漏,被VisualStudioCRT调试系统检测到。我将我的程序缩减为以下内容,但仍然显示内存泄漏C++ 在一个非常简单的程序中检测到内存泄漏。怎么办?,c++,visual-studio-2012,memory-leaks,msvcrt,C++,Visual Studio 2012,Memory Leaks,Msvcrt,我的大程序内存泄漏,被VisualStudioCRT调试系统检测到。我将我的程序缩减为以下内容,但仍然显示内存泄漏 #include "stdafx.h" #include "crtdbg.h" int main() { int tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); _CrtSetDbgFlag(tmp | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); int* k = n
#include "stdafx.h"
#include "crtdbg.h"
int main()
{
int tmp = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
_CrtSetDbgFlag(tmp | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
int* k = new int(8);
delete k;
return 0;
}
当我在Visual Studio 2012系统中运行它时,我看到以下内容:
Detected memory leaks!
Dumping objects ->
{65} normal block at 0x00663008, 4424 bytes long.
Data: <X #f > 58 CF 14 00 90 23 66 00 01 00 00 00 00 00 00 00
{64} normal block at 0x00662390, 4 bytes long.
Data: < > 00 C3 14 00
Object dump complete.
我的系统是:
- 微软Visual Studio专业版2012
- 版本11.0.61030.00更新4
cppuTest
可能在您不知道的情况下应用于您的简单项目
我建议您创建一个全新的Win32控制台应用程序,复制并粘贴代码,然后重新测试。确保新项目没有其他依赖项。只是在安装了Delaker的clean VS 2012安装中进行了尝试。无泄漏显示。在决赛中没有CRT的输出 堆栈跟踪中提到的MemoryLeakWarningPlugin是什么?似乎这是CppUTest的一部分(我用谷歌搜索了一下)
我认为要么MemoryLeakWarningPlugin本身泄漏,要么它以某种方式破坏了CRT诊断系统。如果您只调用
\u crtsetdbglag(\u CRTDBG\u ALLOC\u MEM\u DF | u CRTDBG\u LEAK\u CHECK\u DF)会发生什么情况代码>不将它们与现有位集组合?@sjdowling不更改您链接到的运行库是什么?如果是Multi-thread Debug DLL
,将其更改为Multi-thread Debug
,并查看在重建和重新运行应用程序后问题是否仍然存在。@PaulMcKenzie我已经在使用多线程调试(/MTd)
(从项目设置复制此项)@anatolyg-据我所知,调用堆栈中的这些函数,不是Visual C++运行时内部函数。使用谷歌将我带到这里:。我建议您创建一个全新的、原始的Win32控制台应用程序,并重新测试代码。
> test_it.exe!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 393 C++
test_it.exe!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 239 C++
test_it.exe!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine) Line 302 C++
test_it.exe!malloc(unsigned int nSize) Line 56 C++
test_it.exe!_PlatformSpecificMalloc() Unknown
test_it.exe!MemoryLeakWarningPlugin::ignoreAllLeaksInTest(void) Unknown
test_it.exe!operator new(unsigned int) Unknown
test_it.exe!MemoryLeakWarningPlugin::getGlobalDetector(void) Unknown
test_it.exe!std::error_condition::value(void) Unknown
test_it.exe!operator new(unsigned int) Unknown
test_it.exe!main() Line 9 C++