我正在经历一些奇怪的行为。在调用 delete [] pOutputStr 语句期间,我有一段代码崩溃了(仅限于发布模式)。
void MyFunction()
{
char* pOutputStr = new char[100];
//my other code which is nowhere related to this
delete[] pOutputStr; **// here its failing**
pOutputStr = NULL;
}
请注意:当我尝试在发布模式下进行调试时,我注意到代码流将进入调试模式。请参阅以下代码:
void __CRTDECL operator delete(void* const block) noexcept
{
#ifdef _DEBUG
_free_dbg(block, _UNKNOWN_BLOCK); // my code comes here instead of else block which is release mode
#else
free(block); // ideally it should come here, since its release mode.
#endif
}
我怀疑我的代码_DEBUG中的某个地方已定义,但事实并非如此。我还检查了项目属性的预处理器部分,我也可以看到定义了NDEBUG。
请告诉我,这可能是什么问题?
将我的代码从VS2012迁移到VS2017版本后出现此问题。
请告诉我这里缺少什么?
答案 0 :(得分:0)
如果单步执行Release代码,请进入void __CRTDECL operator delete(void* const block) noexcept
{
#ifdef _DEBUG
_free_dbg(block, _UNKNOWN_BLOCK); // my code comes here instead of else block which is release mode
#else
//...
}
分支:
#define _DEBUG
这意味着你的代码中有某处:
_Debug
或类似的东西。
如果定义了#define _DEBUG
,首先检查项目编译器设置。
我通常会退出IDE,然后点击我的指挥官"应用程序并使用我的项目搜索整个文件夹,查找包含文本{{1}}。
的文件这个档案是你的罪魁祸首。