On Wednesday, November 28, 2018 at 12:53:57 AM UTC-8, Jori Mäntysalo wrote:
>
> The code can be made a little shorter: 
>
> def check(n): 
>      while True: 
>          for P in Posets(n): 
>              x = P._hasse_diagram.moebius_function(0, n-1) 
>          print get_memory_usage() 
>
> It still has the same error limit, i.e. check(6) works but check(7) does 
> not. I played a little with the code, and gc.collect() does not seem to 
> make anything. After a little more I got 
>
>
I think this code most definitely leaks; also with n=6. 

def check(n):
     for j in [1..6]:
         i = 0
         for P in Posets(n):
             x = P._hasse_diagram.moebius_function(0, n-1)
             i += 1
             if i > 2000:
                 break
         print get_memory_usage()

import gc
from collections import Counter
gc.collect()

pre={id(c) for c in gc.get_objects()}
check(6)
gc.collect()
post=Counter(type(o) for o in gc.get_objects() if id(o) not in pre)
sorted(post.iteritems(),key=lambda t: t[1])

finds plenty of HasseDiagram objects on the heap.

You can look at backreference graphs, using "objgraph":
 
objgraph.show_backrefs([o for o in gc.get_objects() if type(o) is 
sage.combinat.posets.hasse_diagram.HasseDiagram][5:6],max_depth=8,filename="graph.dot")

(you may have to experiment with the actual object you take the backrefs 
of; not all of them are so well-connected)

You'll quickly see the object is in some "WeakCachedFunction" (a cached 
__classcall__). The fact that the reference is found indicates the 
HasseDiagram object is a key. Probably the value is something kept alive by 
the key. The cache itself of course lives on a class, so has unlimited 
lifespan. It will take a little bit more work to dig up the actual place 
where the reference loop is made, but hopefully with this information 
someone can find it.

I'm not sure this is the same memory problem the Martin originally stumbled 
on, because there I was not seeing large numbers of objects on the heap.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to