#14711: Weak references in the coercion graph
-------------------------------------+-------------------------------------
Reporter: jpflori | Owner: davidloeffler
Type: defect | Status: needs_review
Priority: critical | Milestone: sage-5.13
Component: number fields | Resolution:
Keywords: memleak, number | Merged in:
field, QuadraticField | Reviewers:
Authors: Simon King | Work issues:
Report Upstream: N/A | Commit:
Branch: | 364b9856b28d7060e3ea9825144de66c8f11ca2a
u/SimonKing/ticket/14711 | Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by SimonKing):
PPS: I just found that Sage's coercion system is clever enough to find a
composite map if `phi` is registered as coerce embedding and `psi` is a
short-cut:
{{{
sage: A = Aclass()
sage: B = Bclass()
sage: C = Cclass()
sage: phi = sage.categories.map.Map(A,B)
sage: A.register_embedding(phi)
sage: psi = C.coerce_map_from(B)
sage: print psi
Generic map:
From: <class '__main__.Bclass'>
To: <class '__main__.Cclass'>
WARNING: This map has apparently been used internally
in the coercion system. It may become defunct in the next
garbage collection. Please use a copy.
sage: print phi
Generic map:
From: <class '__main__.Aclass'>
To: <class '__main__.Bclass'>
WARNING: This map has apparently been used internally
in the coercion system. It may become defunct in the next
garbage collection. Please use a copy.
sage: C.coerce_map_from(A)
Composite map:
From: <class '__main__.Aclass'>
To: <class '__main__.Cclass'>
WARNING: This map has apparently been used internally
in the coercion system. It may become defunct in the next
garbage collection. Please use a copy.
}}}
Here, before discovering and caching the composite map, A keeps B alive
because of the embedding, and C neither keeps A nor B alive. After caching
the composite map, A still keeps B alive, and C still does not keep A
alive, because it only occurs as weak key in a `MonoDict`.
But we have
{{{
sage: len([x for x in gc.get_objects() if isinstance(x,Aclass)])
0
sage: len([x for x in gc.get_objects() if isinstance(x,Bclass)])
1
}}}
So, why is B not garbage collected? To be investigated, I need to hurry
now.
--
Ticket URL: <http://trac.sagemath.org/ticket/14711#comment:128>
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.