简体   繁体   English

使用xml.dom.minidom解析xml的内存泄漏

[英]memory leak parsing xml using xml.dom.minidom

I'm using xml.dom.minidom to parse xml files, somewhat like this: 我正在使用xml.dom.minidom来解析xml文件,如下所示:

import xml.dom.minidom as dom

file= open('file.xml')
doc= dom.parse(file)
# SNIP
doc.unlink()

Even after unlinking the document, the memory usage is at about 120 MiB. 即使取消链接文档后,内存使用量仍约为120 MiB。 When one is actually using the program, causing multiple xml files to be parsed, memory usage climbs to about 300 MiB, which is unacceptable. 当实际使用该程序导致解析多个xml文件时,内存使用量攀升至大约300 MiB,这是不可接受的。

I'm sure the memory leak isn't caused by my code, but by minidom, because even doing just 我确定内存泄漏不是由我的代码引起的,而是由极小的原因引起的,因为即使这样做

doc= dom.parse(file)
doc.unlink()

produces the same result. 产生相同的结果。

Am I doing something wrong, or is this a bug in minidom? 我是在做错什么,还是这是一个小小的错误?

PS: I'd prefer to stick to minidom, because there's a lot of xml parsing happening in my code, and I'd rather not completely rewrite all of it, but I will do it if there's no other choice. PS:我宁愿坚持最小化,因为在我的代码中发生了很多 xml解析,并且我不想完全重写所有这些解析,但是如果没有其他选择,我会做的。

I am also observing the same issues with minidom! 我也观察到了相同的问题! And we are not alone. 我们并不孤单。 See for example here . 例如参见这里

There it is suggested to use an other XML implementations with python binding like 在那里建议使用其他具有python绑定的XML实现,例如

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM