Opened 7 years ago

Last modified 21 months ago

#18426 new enhancement

Memory leaks in RootSystem — at Version 2

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 nthiery)

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 that can never be deleted. Moreover, the B3 root system then holds a (strong) reference to the C3 root system, so the C3 root system never gets collected either.

Some data:

sage: from collections import Counter
sage: import gc
sage: gc.collect()
91
sage: pre = {id(a) for a in gc.get_objects()}
sage: get_memory_usage()
1022.7890625
sage: for n in range(5,3000):
    RS = RootSystem(['A',n])
....:     
sage: gc.collect()
0
sage: get_memory_usage()
1031.359375
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 (2)

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.

comment:2 Changed 7 years ago by nthiery

  • Description modified (diff)

Hi Travis!

I am sure there are plenty of other similar situations of cross-referencing parents (e.g. in SymmetricFunctions). How critical do you think this specific situation is? I mean: do you foresee people creating thousands of different root systems in the same Sage session?

Cheers,

Nicolas

Note: See TracTickets for help on using tickets.