ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 21 Mar 2019 16:57:45 -0500Memory usage strictly increasing on Sage interactive shellhttp://ask.sagemath.org/question/45863/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.jbThu, 21 Mar 2019 16:57:45 -0500http://ask.sagemath.org/question/45863/Memory leaks with matrix multiplication over GF(2)http://ask.sagemath.org/question/43769/memory-leaks-with-matrix-multiplication-over-gf2/Hello everyone,
I have memory leaks when I run this program:
#### Memory leaks with sage 8.3 and sage 8.1 !!!
n = 8
X = zero_vector(GF(2), n)
M = zero_matrix(GF(2), n, n)
for _ in range(10000000):
Y = M * X
I use debian buster and sage-8.3-Debian_GNU_Linux_9-x86_64.
Is there something I'm doing wrong?
Thanks !agrospelWed, 26 Sep 2018 04:18:13 -0500http://ask.sagemath.org/question/43769/Memory leak somewhere?http://ask.sagemath.org/question/34364/memory-leak-somewhere/My code is using massive amounts of memory (eventually), which I don't think should be the case. The memory use slowly increases until my computer runs out of memory. I tried enabling garbage collection, but that didn't help (or didn't help enough). I don't see any reason why this should use more and more memory. It takes somewhere between 5 and 10 hours for this program to use up my 16 GB of memory, but that memory user is increasing is clear quickly.
import numpy
trials = 5800
length = 5000
mean = 0
results = [0]*trials
data = [0]*length
for i in range(trials):
data[0] = numpy.random.normal(0,1)
for j in range(1, length):
data[j] = data[j-1] + numpy.random.normal(0,1)
for k in range(2, length):
if data[k] > 2*sqrt(k*log(log(k+1))):
results[i] += 1
mean += results[i]vukovSun, 07 Aug 2016 13:04:22 -0500http://ask.sagemath.org/question/34364/High memory usage when substituting variableshttp://ask.sagemath.org/question/29444/high-memory-usage-when-substituting-variables/I need to make a lot of variable substitutions in multivariate polynomials. However, I only need to store one polynomial at a time and I only need to make one substitution at a time. Nonetheless sage uses a lot of memory. This memory is not freed until sage is killed.
Here is a small example:
var("x y z")
# A polynomial in three variables (The Trott quartic):
poly=12^2*(x^4+y^4)-15^2*(x^2+y^2)*z^2+350*x^2*y^2+9^2*z^4
poly=poly.polynomial(ZZ)
pnt=[1,2,3]
# Makes a certain variable subsitution, defined by pt, n times.
def test_subs(f,pt,n):
for i in xrange(n):
temp=f.substitute(x=x+pt[0]*z,y=y+pt[1]*z,z=pt[2]*z)
#temp=f(x=x+pt[0]*z,y=y+pt[1]*z,z=pt[2]*z) #This also uses a lot of memory.
When i run `test_subs(poly,pnt,100000)` I can see the memory usage ticking up from around 1% up to nearly 2%. if I then run the function again the ticking starts at 2%, and so on. In the real problem I have my program eventually fills up all memory and then crashes.
Can you see why this is happening and do you know how to prevent it from happening?Olof BergvallTue, 15 Sep 2015 04:09:49 -0500http://ask.sagemath.org/question/29444/