Skip to content

Instantly share code, notes, and snippets.

@grokcode
Last active December 14, 2018 17:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save grokcode/f89d5c5f1831c6bc373be6494f843de3 to your computer and use it in GitHub Desktop.
import gc
from io import StringIO
import xml.etree.ElementTree as etree
import objgraph
def parse_xml():
xml = """
<LEVEL1>
</LEVEL1>
</ROOT>
"""
parser = etree.iterparse(StringIO(initial_value=xml))
for _, elem in parser:
if elem.tag == 'LEVEL1':
break
def run():
parse_xml()
gc.collect()
uncollected_elems = objgraph.by_type('Element')
print(uncollected_elems)
objgraph.show_backrefs(uncollected_elems, max_depth=15)
if __name__ == "__main__":
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment