#14711: Memleak when creating QuadraticField
-------------------------------------------------+-------------------------
Reporter: jpflori | Owner:
Type: defect | davidloeffler
Priority: critical | Status: new
Component: number fields | Milestone: sage-5.13
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:82 SimonKing]:
> - Maps registered by `P.register_coercion(mor)` are the backbone of the
discover_coercion algorithm. Hence, they need to be kept healthy as long
as `P` lives.
It's not clear to me this is the case. If `mor` is a map from S to P then
`P.register_coercion(mor)` ensures the coercion system knows how to map an
element from S into P. Why is it important to maintain this information
for the lifetime of P? If S ceases to exist, then one would not need to
map elements from S to P. Why do we need to ensure S keeps existing?
Shouldn't P have a reference to S independent of the coercion system if
P's health depends on the existence of S? I think the coercion system is
there to keep track of relations between existing objects, not to keep
objects in existence (although this might be a side-effect of keeping
track of relations between other objects).
> - If P has a coerce embedding then this embedding needs to be kept
healthy as long as P lives.
I presume this is the function of the `_embedding` coercion attribute? So
it looks like we already have that. What if we want multiple embeddings?
> - `P.register_coercion(mor)` keeps a strong reference to `mor.domain()`
in a new attribute `P._registered_domains` (which is a list). All other
maps in the coercion system will be weakened.
So what means are there available to add a coercion without tying the
lifespan of one to the other? Shouldn't it be possible to specify such
things too?
> - We store the map phi found by `P.discover_coercion(Q)` in
`P._coerce_from_hash`, which is a monodict. In particular, if Q will be
garbage collected, then phi is immediately removed from the cache, and
thus the strong reference of phi to the codomain P will not prevent P from
garbage collection.
It never did prevent collection: The reference to phi is held by P, so the
reference from phi to P would be recognized as a cycle, so the cyclic GC
would find it (and parents usually are involved in cycles already, so
cyclic GC is their only chance for being reclaimed anyway). Your statement
is still true.
> And concerning a safe user interface: Perhaps we can do without. Namely,
we could make it so that the string representation of a weakened map will
consist of a warning, suggesting to use a copy. In this way, it would be
sufficiently likely that the user wouldn't have too many bad surprises.
Hm, we'll see.
--
Ticket URL: <http://trac.sagemath.org/ticket/14711#comment:83>
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.