Repository navigation
Release parsed tree and source lines after convert() (#1725) - #1727
Open
tony1233200 wants to merge 1 commit into
Open
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
…#1725) Clear the references that kept the last document alive on a reused Markdown instance: source lines after parsing, the parsed tree after serialization, and InlineProcessor's parent_map/stashed_nodes at the end of its run. Measured with tracemalloc, retained memory after reset() drops from MiBs to ~0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #1725
After
Markdown.convert()serializes a document, the parsedElementTreestayed reachable fromself.parser.root,InlineProcessor.parent_map/stashed_nodesheld every element, andself.lineskept the split source — so a reused instance (the documented MkDocs/Pelican pattern of one instance +reset()between documents) held onto the last document's full tree.This clears each reference once its stage is done with it:
self.lines = []afterparseDocument()root,newRootandself.parser.rootset toNoneafter serializingInlineProcessor.parent_map/stashed_nodesreset to empty dicts at the end ofrun()(both are rebuilt at the start of every run)Verified with
tracemallocon the repo's owndocs/folder: retained memory afterreset()drops to ~0 MiB (the issue measured 2.7 MiB retained on a 0.29 MiB source before the fix). Repeated converts on one instance still produce identical output.AI Assistance Disclosure
AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.
AI tools were use to assist with the following:
(AI assistant: Muse, used as a coding agent; the fix and tests were run and verified locally.)
Checklist