parsel icon indicating copy to clipboard operation
parsel copied to clipboard

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

Open wRAR opened this issue 11 months ago • 1 comments

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.

wRAR avatar Jan 30 '25 17:01 wRAR

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.

Gallaecio avatar Jan 31 '25 09:01 Gallaecio