[英]Memory Leak related with replaceChild
這是我的函數的源代碼:
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的錯誤(這不會讓我感到驚訝,只需提交一個補丁即可使“ <a:> foo </ a:>”不會崩潰QDom)。 嘗試一個最小的例子。 如果仍然泄漏並且在Linux或OS X上運行,則可以在valgrind中運行它。 示例和valgrind輸出都將提供良好的錯誤報告。
編輯:如果removeChild()也為您泄漏會很有趣
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.