Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Memory usage strictly increasing on Sage interactive shell

Hello,

I executed the following script on the Sage interactive shell on Ubuntu 18.04 (on SageMath version 8.7.beta5):

sage: import gc
sage: t = 100000
sage: l = [n for n in xrange(t,t+100)]
sage: ll = []
sage: for x in l:
....:     s = 0
....:     for n in xrange(0,x):
....:         s += cos(RDF(2)*RDF(pi)*RDF(n)/RDF(x))
....:     ll.append([x, s])
....:     del(s)
....:     print "memory usage: " + str(get_memory_usage()) + ", gc: " + str(gc.collect())
....:
memory usage: 5824.5546875, gc: 277
memory usage: 5828.3046875, gc: 0
memory usage: 5832.0546875, gc: 0
memory usage: 5836.0546875, gc: 0
                :
memory usage: 6203.5546875, gc: 0
memory usage: 6207.5546875, gc: 0

As we can see the memory usages, it increases by about 4 MB per each step. Thus, after completed, it increased around 400 MB in total. It is frustrating since it eventually eats up all memories in my system as the size of the input list grows and gc.collect() does not seem to help.

I suspect that there were memory leaks or Sage(or Python) stored all the values of cos() and never freed them for some reasons while the shell not killed.

Can someone please explain what was going on and suggest how to avoid this unwanted memory consumption? Thank you in advance.

Memory usage strictly increasing on Sage interactive shell

Hello,

I executed the following script on the Sage interactive shell on Ubuntu 18.04 (on SageMath version 8.7.beta5):

sage: import gc
sage: t = 100000
sage: l = [n for n in xrange(t,t+100)]
sage: ll = []
sage: for x in l:
....:     s = 0
....:     for n in xrange(0,x):
....:         s += cos(RDF(2)*RDF(pi)*RDF(n)/RDF(x))
....:     ll.append([x, s])
....:     del(s)
....:     print "memory usage: " + str(get_memory_usage()) + ", gc: " + str(gc.collect())
....:
memory usage: 5824.5546875, gc: 277
memory usage: 5828.3046875, gc: 0
memory usage: 5832.0546875, gc: 0
memory usage: 5836.0546875, gc: 0
                :
memory usage: 6203.5546875, gc: 0
memory usage: 6207.5546875, gc: 0

As we can see the memory usages, it increases by about 4 MB per each step. Thus, after completed, it increased around 400 MB in total. It is frustrating since it eventually eats up all memories in my system as the size of the input list grows and gc.collect() does not seem to help.

I suspect that there were memory leaks or Sage(or Python) stored all the values of cos() and never freed them for some reasons while the shell not killed.

Can someone please explain what was going on and suggest how to avoid this unwanted memory consumption? Thank you in advance.

Memory usage strictly increasing on Sage interactive shell

Hello,

I executed the following script on the Sage interactive shell on Ubuntu 18.04 (on SageMath version 8.7.beta5):

sage: import gc
sage: t = 100000
sage: l = [n for n in xrange(t,t+100)]
sage: ll = []
sage: for x in l:
....:     s = 0
....:     for n in xrange(0,x):
....:         s += cos(RDF(2)*RDF(pi)*RDF(n)/RDF(x))
....:     ll.append([x, s])
....:     del(s)
....:     print "memory usage: " + str(get_memory_usage()) + ", gc: " + str(gc.collect())
....:
memory usage: 5824.5546875, gc: 277
memory usage: 5828.3046875, gc: 0
memory usage: 5832.0546875, gc: 0
memory usage: 5836.0546875, gc: 0
                :
memory usage: 6203.5546875, gc: 0
memory usage: 6207.5546875, gc: 0

As we can see the memory usages, it increases by about 4 MB per each step. Thus, after completed, it increased around 400 MB in total. It is frustrating since it eventually eats up all memories in my system as the size of the input list grows and gc.collect() does not seem to help.

I suspect that there were memory leaks or Sage(or Python) stored all the values of cos() and never freed them for some reasons while the shell not killed.

Can someone please explain what was going on and suggest how to avoid this unwanted memory consumption? Thank you in advance.