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

 With the following done, Sage starts:
 - Having the usual strong references of homsets to domain and codomain.
 - Having maps by default as "usual" elements with strong references to
 domain and codomain.
 - `self._parent=None` for maps registered by the coercion model,
 overriding the `self.parent()` method by something that tries to
 reconstruct the parent from domain and codomain.

 Moreover, it fixes the memleak:
 {{{
 sage: Q = QuadraticField(-5)
 sage: C = Q.__class__.__base__
 sage: import gc
 sage: _ = gc.collect()
 sage: numberQuadFields = len([x for x in gc.get_objects() if isinstance(x,
 C)])
 sage: del Q
 sage: _ = gc.collect()
 sage: numberQuadFields == len([x for x in gc.get_objects() if
 isinstance(x, C)]) + 1
 True
 }}}

 Granted, it is possible to get a map in an invalid state (at least with
 the not-yet-posted version of my branch):
 {{{
 sage: Q = QuadraticField(-5)
 sage: phi = CDF.convert_map_from(Q)
 sage: del Q
 sage: _ = gc.collect()
 sage: phi.parent()
 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call
 last)
 <ipython-input-14-5708ddd58791> in <module>()
 ----> 1 phi.parent()

 /home/king/Sage/git/sage/local/lib/python2.7/site-
 packages/sage/categories/map.so in sage.categories.map.Map.parent
 (sage/categories/map.c:3023)()

 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?

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