且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

内存泄漏解析R中的XML

更新时间:2023-11-25 13:53:52

我成功解决了与您非常相似的问题.

I succeed in correcting a problem very similar as yours.

我的文档是一个简单的xml文档:

My document is a simple xml doc:

doc = xmlParse(file_path)

doc = xmlParse(file_path)

我采用了 Duncan Temple Lang 中有关绕过内存管理的建议在收集子节点中.为此,我首先使用停用了终结器的getNodeSet来收集子节点:

I apply the advise from Duncan Temple Lang about by-passing the memory management in collecting subnodes. For that purpose, I first gather subnodes with getNodeSet with deactivating finalizer:

nodeset = getNodeSet(doc, xml_path, addFinalizer = FALSE)

从这个集合中,我可以构建一个子文档并释放它,而不会发生任何内存泄漏:

From this set, I can build a subdoc and free it without any memory leak:

subxml = subdoc(nodeset[[1]])
# ... do plenty of sapply
free(subxml)

最后,我强制对象按该顺序释放:

At the end, I force the objects to be released, in that order:

free(doc)
rm(nodeset)

有了这些,我再也没有内存泄漏了.希望能对您有所帮助!

With all of this, I have no memory leak anylonger. Hope it can help!