#12313: Fix yet another memory leak caused by caching of coercion data
-------------------------+--------------------------------------------------
   Reporter:  SimonKing  |          Owner:  rlm                     
       Type:  defect     |         Status:  new                     
   Priority:  major      |      Milestone:  sage-5.0                
  Component:  memleak    |       Keywords:  coercion weak dictionary
Work_issues:             |       Upstream:  N/A                     
   Reviewer:             |         Author:                          
     Merged:             |   Dependencies:  #715                    
-------------------------+--------------------------------------------------

Comment(by SimonKing):

 Memory leaks are quite tricky!!

 The post here is mainly a memo for myself, documenting what went wrong in
 the last couple of days.

 I tried to directly modify my code from #715. The approach was:
 `TripleDict` or `MonoDict` should store the data in lists, with some list
 items being the address of the keys; and in a separate dictionary, a
 `weakref.KeyedRef` with a callback function is preserved.

 And what happened when I replaced `Parent._coerce_from_hash` by a
 `MonoDict`? A memory leak was ''created'' by using weak references!
 Namely,

  * There is a strong reference to `weakref.KeyedRef`.
  * The `weakref.KeyedRef` has a strong reference to the callback function
  * The callback function is an instance of something that I'll call
 `MonoDictEraser` (similar to  the `TripleDictEraser` from #715)
  * The Eraser has a strong reference to the `MonoDict`
  * The `MonoDict` has a strong reference to the coerce map.
  * The coerce map has a strong reference to domain and codomain
  * Hence, domain and codomain can't be collected.

 I think the best place to break the reference chain is from the Eraser to
 the `MonoDict`. Perhaps one could do the same thing at #715, rather than
 having a weak reference to the underlying set of an action?

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