#15424: A coercion-related memory leak
-----------------------------+-------------------------
       Reporter:  SimonKing  |        Owner:
           Type:  defect     |       Status:  new
       Priority:  major      |    Milestone:  sage-5.13
      Component:  memleak    |   Resolution:
       Keywords:             |    Merged in:
        Authors:             |    Reviewers:
Report Upstream:  N/A        |  Work issues:
         Branch:             |       Commit:
   Dependencies:             |     Stopgaps:
-----------------------------+-------------------------

Comment (by nbruin):

 I tried to see where the reference can be coming from:
 {{{
 %cpaste
 import gc
 from sage.structure.coerce_dict import *
 def all_referrers(c,X):
     found_IDs=set()
     R=[]
     new=gc.get_referrers(c)
     found_IDs.add(id(new))
     found_IDs.add(id(R))
     found_IDs.add(id(globals()))
     while len(new)>0:
         r=new.pop()
         if id(r) in found_IDs or type(r) not in X:
             print "skipping",type(r)
             continue
         R.append(r)
         found_IDs.add(id(r))
         new.extend(gc.get_referrers(r))
         print "type(r)=%s len(R)=%s len(new)=%s"%(type(r),len(R),len(new))
     return R

 def getR():
     K = IntegerModRing(111115)
     C = type(K)
     phi = K.coerce_map_from(ZZ)
     del phi
     #vary this line:
     x = K.one()*2
     #del K,x
     _ = gc.collect()
     X=set([list,dict,tuple,
            RingHomset_generic_with_category,
            sage.rings.finite_rings.integer_mod.Integer_to_IntegerMod,
            TripleDict, MonoDict, C])
     R=all_referrers(list(c for c in gc.get_objects() if
 isinstance(c,C))[0],X)
     return R
 --
 RingHomset_generic_with_category=type(ZZ.Hom(QQ))
 R=getR()
 }}}
 and I found that with `x=K.one()*2` there is also a !TripleDict that show
 up. It's fairly big (44 entries) and the entries all seem to be of the
 form `D[domain,codomain,None]=morphism from domain to codomain` (or `None`
 entries). Since the morphism has a strong reference to the codomain, this
 would keep our ring alive [it doesn't seem like the kind of dictionary
 that can afford to be weak on its values]. Judging from the entries, this
 dictionary is a global one. I think there is a ticket somewhere that
 mentions the same phenomenon (also doing arithmetic), in the context of
 finite fields. Somewhere from the era when we started to work on #715 in
 earnest.

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