KITFORMA · EDITORIAL ANSWER
Why does caching a method appear to keep old objects alive?
KitForma editorial guide. An `lru_cache` retains references to cached arguments and results. For a method, `self` is part of the cache key, which can extend instance lifetime.
Step-by-step answer
lru_cache retains references to cached arguments and results. For a method, self is part of the cache key, which can extend instance lifetime.
Inspect cache size with cache_info, set a sensible bound, and clear the cache at an intentional lifecycle boundary. Prefer caching a pure function of small immutable inputs when that matches the work. Test object reclamation and memory after many short-lived instances. Cached results are shared objects; mutating one can surprise later callers. The cache is not a freshness policy, and thread-safe cache bookkeeping does not guarantee that a miss computes only once under concurrent calls.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.