这是我的函数的源代码:
bool FieldModel::updateNode(QDomNode &node,const QString &parent){
QDomElement rootOfTag;
rootOfTag=fieldState.firstChild().firstChildElement(parent);
qDebug()<<"Before"<<fieldState.toString();
QDomNodeList sameTags=rootOfTag.elementsByTagName(node.firstChild().toElement().tagName());
for(uint i=0;i<sameTags.length();i++){
QDomNode nodeToReplace=sameTags.item(i);
if(nodeToReplace.toElement().attribute("id")==node.firstChild().toElement().attribute("id")){
nodeToReplace.parentNode().replaceChild(node,nodeToReplace);//Cause Memory Leak
qDebug()<<"After"<<fieldState.toString();
return true;
}
}
insertNode(node,parent);
return true;
}
我的程序的内存使用量严格增加,但是当我删除 nodeToReplace.parentNode().replaceChild(node,nodeToReplace);
行时,程序使用稳定的内存量。
我监控了 fieldState(QDomDocument)
,当我使用 replaceChild
时它没有增长(我做了一些小改动)。有什么问题?
谢谢。
最佳答案
在我看来像是一个 QDom 错误(这不会让我太吃惊,只是提交了一个补丁让“
编辑:如果 removeChild() 也为您泄漏会很有趣
关于c++ - 与 replaceChild 相关的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3501441/