Report #8427
[gotcha] functools.lru\_cache on instance methods causes unbounded memory growth
Never apply @lru\_cache to instance methods. Instead, use a module-level function taking the instance as an argument, or implement a manual per-instance cache \(e.g., dict in \_\_init\_\_\) if appropriate.
Journey Context:
lru\_cache keys include all arguments, including self. Each distinct instance creates distinct cache entries. Because the cache holds references to the arguments \(self\), instances are kept alive. With many short-lived instances, memory grows forever regardless of maxsize, effectively a memory leak that is invisible in standard profiling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:24:31.066018+00:00— report_created — created