#12357: Make groupoids garbage collectable
---------------------------------+------------------------------------------
Reporter: SimonKing | Owner: rlm
Type: defect | Status: positive_review
Priority: major | Milestone: sage-pending
Component: memleak | Keywords: groupoid cache Cernay2012
Work_issues: rebase rel #11943 | Upstream: N/A
Reviewer: | Author: Simon King
Merged: | Dependencies: #715, #12313, #11943
---------------------------------+------------------------------------------
Old description:
> Currently, the groupoid of an object P can not be garbage collected, even
> when deleting P.
>
> Even worse: The persistence of `Groupoid(P)` also prevents P from being
> garbage collected.
>
> The attached patch aims at solving it: An external reference to either P
> or `Groupoid(P)` is enough to keep both alive. But without an external
> reference, both P and `Groupoid(P)` become collectable.
>
> Example from the docs:
> {{{
> sage: P = GF(151)['x','y']
> sage: n = id(Groupoid(P))
> sage: import gc
> sage: _ = gc.collect()
> sage: n == id(Groupoid(P)) # indirect doctest
> True
>
> Thus, the groupoid is cached. But when deleting ``P``, its
> groupoid can be garbage collected as well::
>
> sage: del P
> sage: _ = gc.collect()
> sage: P = GF(151)['x','y']
> sage: n == id(Groupoid(P))
> False
>
> TESTS:
>
> We test against some corner cases::
>
> sage: Groupoid(None)
> Traceback (most recent call last):
> ...
> TypeError: Groupoid of None is not defined
> sage: Groupoid(1)
> Traceback (most recent call last):
> ...
> TypeError: 1 must either allow attribute assignment or be
> instances of <type 'sage.structure.parent.Parent'>
> sage: class A: pass
> sage: a = A()
> sage: Groupoid(a)
> Groupoid with underlying set <__main__.A instance at ...>
> sage: Groupoid(a) is Groupoid(a)
> True
> }}}
New description:
Currently, the groupoid of an object P can not be garbage collected, even
when deleting P.
Even worse: The persistence of `Groupoid(P)` also prevents P from being
garbage collected.
The attached patch aims at solving it: An external reference to either P
or `Groupoid(P)` is enough to keep both alive. But without an external
reference, both P and `Groupoid(P)` become collectable.
Example from the docs:
{{{
sage: P = GF(151)['x','y']
sage: n = id(Groupoid(P))
sage: import gc
sage: _ = gc.collect()
sage: n == id(Groupoid(P)) # indirect doctest
True
Thus, the groupoid is cached. But when deleting ``P``, its
groupoid can be garbage collected as well::
sage: del P
sage: _ = gc.collect()
sage: P = GF(151)['x','y']
sage: n == id(Groupoid(P))
False
TESTS:
We test against some corner cases::
sage: Groupoid(None)
Traceback (most recent call last):
...
TypeError: Groupoid of None is not defined
sage: Groupoid(1)
Traceback (most recent call last):
...
TypeError: 1 must either allow attribute assignment or be
instances of <type 'sage.structure.parent.Parent'>
sage: class A: pass
sage: a = A()
sage: Groupoid(a)
Groupoid with underlying set <__main__.A instance at ...>
sage: Groupoid(a) is Groupoid(a)
True
}}}
Apply:
- [attachment:trac12357_internal_strong_groupoid_cache.patch]
- [attachment:trac12357_reviewer.patch]
--
Comment(by SimonKing):
Done!
Apply trac12357_internal_strong_groupoid_cache.patch
trac12357_reviewer.patch
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12357#comment:11>
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.