Skip to content

Conversation

@chaen
Copy link
Contributor

@chaen chaen commented Oct 31, 2025

cached prevents garbage collection

import functools
import objgraph   # pip install objgraph
import gc


class Foo:
    # This cache is held somewhere in global memory, and prevents Foo objects from being reaped
    @functools.cache
    def func(self, key):
        return key + key

for i in range(10):
    Foo().func(i)


gc.collect()
print(f"Foo: {objgraph.by_type('Foo')}")  # 10 objects

BEGINRELEASENOTES

*Framework
FIX: use cachedmethod instead of cached in ProxyDB

*TS
FIX: use cachedmethod instead of cached in Utilities

ENDRELEASENOTES

@chaen chaen marked this pull request as ready for review November 13, 2025 08:48
@chaen chaen requested a review from fstagni as a code owner November 13, 2025 08:48
@fstagni
Copy link
Contributor

fstagni commented Nov 13, 2025

I do not fully understand here:

  • your example uses functools.cache, not cachetools.cached
  • how did you discover? any reference?
  • did you try with the cachedmethod?

@fstagni fstagni merged commit 6ea1b63 into DIRACGrid:integration Nov 17, 2025
21 checks passed
@DIRACGridBot DIRACGridBot added the sweep:ignore Prevent sweeping from being ran for this PR label Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sweep:ignore Prevent sweeping from being ran for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants