Skip to content

gh-93618: Document the memory usage of the incremental parsers - #156763

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-93618-iterparse-memory-docs
Open

gh-93618: Document the memory usage of the incremental parsers#156763
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-93618-iterparse-memory-docs

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 1, 2026

Copy link
Copy Markdown
Member

The documentation said that iterparse() "can be useful when you're reading a large XML document and don't want to hold it wholly in memory", but the tree is only built incrementally, it is not freed incrementally: every parsed element is kept until the whole document is read.

The claim is replaced with an explanation and two examples for common cases: clearing large processed elements, and removing the processed children of an element with many of them. Both are in the "Pull API for non-blocking parsing" section, because this applies to XMLPullParser as well.

They are not universal, they only give an idea; the note ends with the way to avoid the tree entirely, an XMLParser with a custom target.

It was said that iterparse() can be useful for reading a large document
without holding it wholly in memory, but the tree is only built
incrementally, it is not freed incrementally.  Document how to remove the
processed elements, and that a custom target does not build a tree at all.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34331034 | 📁 Comparing f9f3101 against main (faf4e52)

  🔍 Preview build  

1 file changed
± library/xml.etree.elementtree.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir skip news

1 participant