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

 Really, it's a bit silly that `WeakValueDictionary` does a lookup by key
 on its removal callback.

 An alternative, better, but more laborious solution is to improve
 `WeakValueDictionary`. What we need is a dictionary with an extra method:
 {{{
     def delete_by_hash_and_value_id(self,hash,id):
         find bucket based on hash
         find entry by walking the bucket to find the given *value* id.
         delete that entry
 }}}
 Then your `WeakValueDictionary` can inherit from it and do:
 {{{
     def __setitem__(self,key,value):
         r=KeyedRef(value,(h,id(value)),
             lambda ref:
 self.delete_by_hash_and_value_id(ref.key[0],ref.key[1])
         super(self).__setitem__(key,r)
 }}}
 The most attractive approach would be to subclass dict, but getting access
 to its internal storage to do this modified search would be painful.

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