-
-
Notifications
You must be signed in to change notification settings - Fork 660
Closed
Labels
Milestone
Description
The documentation says that UniqueRepresentation uses weak refs, but this was switched over to the @
cached_method decorator. The latter does currently use strong references, so unused unique parents stay in memory forever:
import sage.structure.unique_representation
len(sage.structure.unique_representation.UniqueRepresentation.__classcall__.cache)
for i in range(2,1000):
ring = ZZ.quotient(ZZ(i))
vectorspace = ring^2
import gc
gc.collect()
len(sage.structure.unique_representation.UniqueRepresentation.__classcall__.cache)
Related tickets:
- Use weak references to cache homsets #11521 (needs review, introducing weak references for caching homsets), and
- Parents probably not reclaimed due to too much caching #715 (needs review, using weak references for caching coerce maps).
- Weak references in Polynomial Ring cache #5970 (the polynomial rings cache use strong references, which may now be a duplicate, as I introduce the weak cache in Parents probably not reclaimed due to too much caching #715)
Further notes:
- not everything in Python can be weakref'ed, for example
None
cannot. - some results that are expensive to compute should not just be cached by a weak reference. Perhaps there is place for a permanent cache, or maybe some minimal age before garbage collecting it.
Apply
CC: @simon-king-jena @jdemeyer @mwhansen @vbraun @jpflori
Component: memleak
Keywords: UniqueRepresentation cached_method caching
Author: Simon King
Reviewer: Nils Bruin
Merged: sage-5.7.beta1
Issue created by migration from https://trac.sagemath.org/ticket/12215