Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of functools.lru_cache or functools.cache on methods can lead to memory leaks #312

Open
wRAR opened this issue Jan 30, 2025 · 1 comment

Comments

@wRAR
Copy link
Member

wRAR commented Jan 30, 2025

ruff detects that @lru_cache used on GenericTranslator.css_to_xpath() and HTMLTranslator.css_to_xpath() (added in #109) is not a good idea: "the global cache will retain a reference to the instance, preventing it from being garbage collected", we need to fix or ignore this. I think there are some singletons of these types and maybe we don't use other instances of them but this needs investigating.

@Gallaecio
Copy link
Member

Gallaecio commented Jan 31, 2025

Since we use this to convert expressions that are usually only a few and defined at development time, in code, and not at run time, and we limit the sizes of those caches (to 256), I think we could ignore this issue on those 2 lines. It feels like we are doing something similar to what the re module does when its method get strings instead of compiler patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants