#14711: Memleak when creating QuadraticField
-------------------------------------------------+-------------------------
Reporter: jpflori | Owner:
Type: defect | davidloeffler
Priority: critical | Status: new
Component: number fields | Milestone: sage-5.12
Keywords: memleak, number field, | Resolution:
QuadraticField | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: u/SimonKing/ticket/14711 | Commit:
Dependencies: | Stopgaps:
-------------------------------------------------+-------------------------
Comment (by nbruin):
Replying to [comment:45 SimonKing]:
> {{{
> sage: Q = QuadraticField(-5)
> sage: phi = CDF.convert_map_from(Q)
> sage: del Q
> sage: _ = gc.collect()
> sage: phi.parent()
> ValueError: This map is in an invalid state, domain or codomain have
been garbage collected
> }}}
>
> But the question is: Is there any way to make Q garbage collectable in
the first example but not collectable in the second example?
Yes of course. `CDF.convert_map_from(Q)` should return a copy equivalent
to `phi` with strong references to domain and codomain. If the original
`phi` is a composition of "weak" (coercion generated) maps then all the
components of the returned `phi` should also be strengthened copies.
Note that the full story should be
{{{
sage: Q = QuadraticField(-5)
sage: phi = CDF.convert_map_from(Q)
sage: del Q
sage: _ = gc.collect() #Q is kept alive due to phi
sage: phi.parent() is not None
True
sage: del phi
sage: _ = gc.collect() #now Q gets collected.
}}}
It means that getting safe maps out of the coercion framework is
relatively expensive business, and it means that maps dwelling there must
have some concept of how to make a copy of themselves. It can be fairly
high level: we just need a container that can have fresh
`_domain,_codomain,_parent` slots to reference strongly what's only reffed
weakly (or not at all) on the maps internal to coercion.
I hope this can all happen without incurring too much performance loss:
the weak reference checking and Homspace reconstruction could end up being
slow(ish) in the coercion framework if those operations are done too
often.
--
Ticket URL: <http://trac.sagemath.org/ticket/14711#comment:46>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.