#15367: Empty lists while creating parents
-------------------------------------+-------------------------------------
       Reporter:  roed               |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-5.13
      Component:  coercion           |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Nils Bruin         |    Reviewers:  Simon King
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/nbruin/ticket/15367              |  9022b3226b0439fdb8d48944c3eb175f5499e49b
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by nbruin):

 Hm, perhaps this is a good argument for trying to avoid circular
 structures and hence avoiding encoding erasers via closures and instead do
 it via an eraser class that has a weak reference to the dictionary:
 {{{
 sage: import gc
 sage:
 sage: T=weakref.WeakKeyDictionary()
 sage:
 sage: L=[GF(p) for p in prime_range(1,1000)]
 sage: for i in range(len(L)-1): T[L[i+1]]=L[i]
 sage: del L
 sage: print len(T)
 167
 sage: C=0
 sage: while len(T) > 0:
 ....:         C+=1
 ....:         _=gc.collect()
 ....:
 sage: print C
 167
 }}}
 as you can see, every GC only collects one finite field. This is what one
 should expect: When GC does its analysis, it finds there is only one field
 that is unreachable, so GC collects that. As a knock-on effect, that
 causes another field to be decreffed. However, since that field is part of
 a reference cycle, that doesn't cause its refcount to hit 0. It takes the
 next GC to find that, thanks to the decref, the field is now unreachable
 and hence gets collected.

 In order for GC to be more effective, we should avoid circular references
 if we easily can. So, in our own `WeakValueDictionary` from #13394 as well
 as in `MonoDict` and in `TripleDict`, I think we should have our erasers
 as a class (as we had). So where the argument on
 http://bugs.python.org/issue417795 didn't immediately convince me, now it
 does. We can fix this on a separate ticket if we want to, since #13394 is
 already merged and the slower GC is not really a bug.

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