Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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]

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]