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

 Yes that might work as a workaround for now. The store indeed needs to be
 weak. It could itself be a `WeakValueDictionary`, keyed on the id of the
 `WeakValueDictionaries` it stores. You'd like to put them in a `WeakSet`,
 but they're not hashable.

 If we're unlucky you'll get into an infinite loop, though. It's not
 impossible that sage, upon equality testing, decides to construct some new
 parents to coerce things into in order to compare them. These parents
 would then get created and entered into caches that we might just have
 cleared! If the process involves creating a new category, a dynamic class
 might even end up producing a new `UniqueRepresentation` and enter a new
 cache into our "to clear" dictionary. Dictionaries behave very badly when
 they are modified while being iterated over.

 So: Worth a try for now. Let's do that to get this ticket out the door.

 ----------------------------------------------------------
 '''Future Ticket'''

 I foresee crazy bugs in the future. A `WeakValueDict` with safe removal is
 probably ultimately unavoidable. And is the work really so bad?

 We could just go with roughly the design for `IdKeyDict`, but then using
 Python's hash function and simpler entries. Normal lookup and delete would
 be via hash and then equality on the keys. Special deletion would be by
 hash and id of the value. Once we have a working prototype we can put it
 out there for the Python community. With any luck someone adopts it and
 improves, tunes and optimizes it. I don't think our applications are so
 super time critical. It's all for creation of parents, which is expensive
 anyway.

 Our applications only need a rudimentary `Dictionary` interface, but
 adding the other methods would not be a huge job.

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