prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.1k stars 717 forks source link

fix memory leak for prompt_toolkit.filters.base.Never/Always and inline condition filter #1836

Closed vicalloy closed 4 months ago

vicalloy commented 6 months ago

Reference: https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1835 Never/Always is cached in prompt_toolkit.filters.utils._bool_to_filter, and if it is the first condition, it will hold the filter and cannot be freed.

The inline condition filter will have a different ID after the parent function is called (a new PromptSession is created). It will be cached by some global condition filter (e.g., is_searching), causing the cached size to increase and never be freed.

jonathanslenders commented 4 months ago

Thanks! That makes sense!