Report #62579
[gotcha] \`functools.lru\_cache\` on instance methods causes unbounded memory growth because \`self\` is cached
Use \`@staticmethod\` with explicit parameters, move cache to module-level, or use \`weakref.WeakMethod\` with a custom cache; never apply \`@lru\_cache\` directly to methods in long-lived objects
Journey Context:
The cache key includes the \`self\` reference, pinning the instance in memory until the cache evicts it \(which may be never for unbounded caches\). Developers assume caching is per-method, but it's per-instance. Alternative: \`@cached\_property\` from \`functools\` is safe for computed properties but doesn't memoize with arguments. The correct pattern is to factor the logic into a standalone function that takes hashable primitive arguments, caching that, and having the method call it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T11:31:22.660040+00:00— report_created — created