为什么我的应用程序在删除时崩溃
Why does my app crash at delete?
while(!m_RemoveNodeList.empty())
{
list<CNode *>::const_iterator const it = m_RemoveNodeList.begin();
CNode * const pNode = *it;
ASSERT(pNode != NULL);
m_NodeList.remove( pNode );
delete pNode; // crashing here
m_RemoveNodeList.pop_front();
}
上面的有时会在删除时崩溃,并产生读冲突异常。会不会是我不小心双重删除了?
m_NodeList和m_RemoveNodeList的类型都是 std::list<CNode *>
我应该提到CNode是其他几个类的基类。然而,这些类都没有在析构函数
你的代码没有明显的崩溃,看起来很好。
只有当副本 CNode*
存储在list<CNode*>
中时才会崩溃;这会让你得到多个delete
。(@ paul .estalella在评论中提到过)
您可以尝试以下方法来捕获,如果有重复 CNode*
。
map<CNode*, int> duplicate;
while(m_RemoveNodeList.size() > 0)
{
list<CNode *>::const_iterator const it = m_RemoveNodeList.begin();
CNode * const pNode = *it;
if(duplicate.find(pNode) == duplicate.end())
duplicate[pNode] = 1;
else
cout<<"Caught: "<<pNode<<endl;
// ...
}
pNode只是对原始文件的引用,而不是副本。不确定remove做了什么,但它确实做了原始的,你有一个双重删除
相关文章:
- 在虚幻引擎中删除NXOpen对象时崩溃
- 无法删除EXE崩溃后,即使进程未显示在任务管理器中
- 删除SDL_PollEvent时程序崩溃
- 删除数组 c++ 崩溃问题
- 在C++中删除指针数组时析构函数崩溃
- 使用自定义上下文菜单删除 QTreeView 项崩溃
- 如果我从single_digits[*num - '0']]中删除'0',为什么这个程序会崩溃)
- 删除动态字符串时程序崩溃
- 当删除上下文属性中的QLIST对象时,QT QML应用程序崩溃
- 删除关键字导致程序崩溃
- C++将自删除推回矢量时崩溃
- 为什么要删除指针崩溃wchar_t?
- 试图删除最后一个std ::向量元素时,程序会崩溃
- 当我尝试删除指针时,我的程序崩溃
- 当我递增指针然后将其删除时,为什么我的程序会崩溃
- qquickvew删除导致应用程序崩溃
- C++:指向对象的指针数组 - 删除元素时程序崩溃>
- c 从范围删除对象的操作员导致崩溃dealloceLoceLoceLoceLoceLoceLoceLoceLoceL
- libpng 的C++抽象导致 malloc 崩溃 -- 删除 2D 数组"Jagged"
- 崩溃删除[]初始化的字符串