#12313: Fix yet another memory leak caused by caching of coercion data
--------------------------------------------------+-------------------------
       Reporter:  SimonKing                       |         Owner:              
                             
           Type:  defect                          |        Status:  
needs_review                             
       Priority:  major                           |     Milestone:  sage-5.3    
                             
      Component:  memleak                         |    Resolution:              
                             
       Keywords:  coercion weak dictionary        |   Work issues:              
                             
Report Upstream:  N/A                             |     Reviewers:  Simon King, 
Jean-Pierre Flori, John Perry
        Authors:  Simon King, Jean-Pierre Flori   |     Merged in:              
                             
   Dependencies:  #11521, #11599, #12969, #12215  |      Stopgaps:              
                             
--------------------------------------------------+-------------------------

Comment (by nbruin):

 It looks like that garbage collection is a great idea! The error is now
 completely reproducible:
 {{{
         sage -t --verbose -force_lib
 "devel/sage/sage/rings/polynomial/pbori.pyx" # Killed/crashed
 }}}
 I've instrumented the remove function on the `WeakValueDictionary` a
 little bit:
 {{{#!diff
         def remove(wr, selfref=ref(self)):
             self = selfref()
             if self is not None:
 +                if type(wr.key) is tuple:
 +                    T=[]
 +                    for t in wr.key:
 +                        try:
 +                            T.append(str(t))
 +                        except:
 +                            T.append("TYPE: %s"%type(t))
 +                    print('removal on key %s'%T)
                 del self.data[wr.key]
         self._remove = remove
         UserDict.UserDict.__init__(self, *args, **kw)
 }}}
 to find (now doctests are failing due to the extra output):
 {{{
 ...
 ***Test Failed*** 18 failures.
 removal on key ['Rational Field', "('z', 'y')", '2', 'False', 'Degree
 reverse lexicographic term order']
 *** glibc detected *** python: double free or corruption (!prev):
 0x0000000006baaaa0 ***
 ...
 Unhandled SIGABRT: An abort() occurred in Sage.
 }}}
 That looks an awful lot like the kind of key that a polynomial ring
 constructor would get. So I guess it's just one of those
 `WeakCachedFunction` dictionaries again. I suspect that part of polybori
 is already torn down when this entry is looked up. It really seems that
 the alternatives are:
  - all those libraries to keep sufficient references to do equality
 testing till the very end
  - make a WeakValueDictionary that doesn't need key comparisons on its
 callback and use that instead
  - convince the release manager that these tickets are important and that
 these doctests are not the fault of these tickets. Remove any components
 that fail due to these changes.
 Option 2 looks quite doable by comparison ... I'd say use a design rather
 similar to `MonoDict`. We probably won't beat `WeakValueDict` for standard
 performance, but we're making another trade-off: we want safe removal,
 even at the price of a little performance. So perhaps two variants,
 `WeakCachedFunction` and `SafeWeakCachedFunction`.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12313#comment:213>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to