#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):

 Replying to [comment:128 SimonKing]:
 > {{{
 > sage: del psi, B, A
 > sage: import gc
 > sage: _ = gc.collect()
 > 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.

 Argh. Because simply I forgot to delete phi...

 Let's try again, this time without leaving a reference to the maps.
 {{{
 sage: import gc
 sage: class Aclass(Parent): pass
 sage: class Bclass(Parent): pass
 sage: class Cclass(Parent):
 ....:    def _coerce_map_from_(self, P):
 ....:        if isinstance(P, Bclass):
 ....:            return sage.categories.map.Map(P,self)
 ....:
 sage: A = Aclass()
 sage: B = Bclass()
 sage: C = Cclass()
 sage: A.register_embedding(sage.categories.map.Map(A,B))
 sage: C.has_coerce_map_from(A)
 True
 sage: del A,B
 sage: gc.collect()
 862
 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)])
 0
 }}}
 So, no leak.

 I think my analysis is now complete: A memory leak caused by composite
 coerce maps will only arise if `C._coerce_map_from_(A)` returns the
 composite map. I have also shown that there is no need to let
 `C._coerce_map_from_(A)` return a composite map.

 Hence, I would argue that `C._coerce_map_from_(A)` returning a composite
 map is a misuse. Granted, it is far from obvious that it is a misuse. I
 feel tempted to investigate how often composite maps are actually returned
 by `_coerce_map_from_`.

--
Ticket URL: <http://trac.sagemath.org/ticket/14711#comment:129>
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.

Reply via email to