#12313: Fix yet another memory leak caused by caching of coercion data
-------------------------+--------------------------------------------------
Reporter: SimonKing | Owner: rlm
Type: defect | Status: needs_work
Priority: major | Milestone: sage-5.0
Component: memleak | Keywords: coercion weak dictionary
Work_issues: | Upstream: N/A
Reviewer: | Author: Simon King
Merged: | Dependencies: #715
-------------------------+--------------------------------------------------
Comment(by SimonKing):
Perhaps you are right, and we could re-organise stuff. Namely, for now
(that's to say: for #715 and for #12313) we could keep strong references
from an action to the underlying set, and from a groupoid to the
underlying set. The unfortunate consequence would be that not all memory
leaks would be fixed. But one could create a new ticket where the idea of
having weak references to the underlying set is tested.
And here is yet another idea, at least for the groupoid case. Let S be any
object and G its groupoid. Ideally, S should keep G alive and G should
keep S alive. Hence, it would be fine to have a strong reference from S to
G and from G to S -- Python's garbage collection can deal with circular
references.
However, there should be no strong references to S or G, unless the user
explicitly provides it. In particular, when creating `Groupoid(S)`, there
should no external cache be used.
Potential solution: The cache for the `Groupoid.__classcall__` should be
in S! Perhaps like this:
{{{
class Groupoid(Category):
@staticmethod
def __classcall__(cls, S):
try:
return getattr(S, '_cached_'+cls.__name__)
except AttributeError:
pass
instance = type.__call__(cls, S)
assert(isinstance(instance,cls))
if instance.__class__.__reduce__ ==
UniqueRepresentation.__reduce__:
instance._reduction = (cls, args, options)
try:
setattr(S, '_cached_'+cls.__name__, instance)
return
except AttributeError:
pass
try:
# Parents have a __cached_methods attribute, by #11115
S.__cached_methods['_cached_'+cls.__name__] = instance
return
except AttributeError:
pass
raise TypeError, "%s instance must either allow attribute
assignment or be instances of %s"(cls, Parent)
}}}
Note that the problem can hardly be solved in the same way for actions.
They need to be stored externally, namely in the coercion model.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:9>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.