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: |
Description (last modified by )
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() 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)]
Note: See
TracTickets for help on using
tickets.
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 toself
.