Opened 7 years ago

Last modified 21 months ago

#18426 new enhancement

Memory leaks in RootSystem — at Version 1

Reported by: tscrim Owned by: sage-combinat
Priority: critical Milestone: sage-6.7
Component: memleak Keywords: memory leak
Cc: sage-combinat, nthiery, slelievre Merged in:
Authors: Travis Scrimshaw Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by tscrim)

RootSystem is currently creating memory leaks in the following way:

Upon creating a root system, say of type B3, this line:

self.dual = RootSystem(self._cartan_type.dual(), as_dual_of=self);

causes the B3 root system to be used as a key in the UniqueRepresentation of the C3 root system (I call it so, but note it is the dual of the B3, which will be different than the honest C3 root system), which is a strong reference. Moreover, the B3 root system then holds a (strong) reference to the C3 root system (and vice versa), so both root systems can never can get collected.

Some data:

sage: from collections import Counter
sage: import gc
sage: gc.collect()
sage: pre = {id(a) for a in gc.get_objects()}
sage: get_memory_usage()
sage: for n in range(5,3000):
    RS = RootSystem(['A',n])
sage: gc.collect()
sage: get_memory_usage()
sage: post = Counter(str(type(a)) for a in gc.get_objects() if id(a) not in pre)
sage: [p for p in post.iteritems() if p[1] > 2000]
[("<class 'weakref.KeyedRef'>", 8985),
 ("<class 'sage.combinat.root_system.type_A.CartanType'>", 2994),
 ("<class 'sage.combinat.root_system.root_system.RootSystem'>", 5990),
 ("<type 'dict'>", 6012),
 ("<type 'tuple'>", 29952)]

Change History (1)

comment:1 Changed 7 years ago by tscrim

  • Description modified (diff)

One possible workaround is to not accept a root system as input, but instead a boolean. Then when it creates the dual root system, and then explicitly sets the dual attribute of the dual root system to self.

Note: See TracTickets for help on using tickets.