Opened 8 years ago

Last modified 7 years ago

#12215 closed defect

Memleak in UniqueRepresentation, @cached_method — at Initial Version

Reported by: vbraun Owned by: rlm
Priority: major Milestone: sage-5.7
Component: memleak Keywords: UniqueRepresentation cached_method caching
Cc: SimonKing, jdemeyer, mhansen, vbraun, jpflori Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:


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

for i in range(2,1000):
    ring = ZZ.quotient(ZZ(i))
    vectorspace = ring^2

import gc

Related tickets:

  • #11521 (needs review, introducing weak references for caching homsets), and
  • #715 (needs a lot of work, eventually aiming at using weak references for caching coerce maps).

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.

Change History (0)

Note: See TracTickets for help on using tickets.