[Tutor] Memory Problem Continued

DORSEY_EDMUND_K@LILLY.COM DORSEY_EDMUND_K@LILLY.COM
Mon Jul 7 12:40:03 2003


This is a multipart message in MIME format.
--=_alternative 005B759405256D5C_=
Content-Type: text/plain; charset="us-ascii"

Previously I was having a memory problem and it was pointed out that the 
range function is quite the memory hog and to use xrange instead. 
Unfortunately this didn't solve the problem (though it did fix a problem 
that I would have probably encountered later with larger data sets)  I 
don't like just pasting code into my email but I'm afraid it's the only 
way I can explain the problem.  So here it goes.  When I start up the 
program and it loads the data set it uses up a fixed amount of memory.  As 
the subvoxelize function shown below continues to run (takes about 5 
minutes before crashing) the memory usage just keeps increasing at a 
constant rate until I run out of memory. 

    def subvoxelize(self, progressFunc=None):
        value = 0
        updateNum = self._numVoxelsOrig/100
        for n in xrange(self._numVoxelsOrig):   #self._numVoxelsOrig has a 
value of around 20 million
            x, y, z = self.to3d(n)                                  #not 
causing any problems with memory
            x2, y2, z2 = x*2, y*2, z*2 
            index0 = x2      + y2*self._newXsize     + z2 * (self._newXY)  
#here is where the problem is and with the subsequent assignments
            index1 = x2+1 + y2*self._newXsize     + z2 * (self._newXY)
            index2 = x2      + (y2+1)*self._newXsize + z2 * (self._newXY)
            index3 = x2+1 + (y2+1)*self._newXsize + z2 * (self._newXY)
            index4 = x2      + y2*self._newXsize     + (z2+1) * 
(self._newXY)
            index5 = x2+1 + y2*self._newXsize     + (z2+1) * (self._newXY)
            index6 = x2      + (y2+1)*self._newXsize + (z2+1) * 
(self._newXY)
            index7 = x2+1 + (y2+1)*self._newXsize + (z2+1) * (self._newXY) 
 #if I don't do these assignments and make each index go to a constant it 
doesn't leak memory
            self._newData[index0] = self._data[n]
            self._newData[index1] = self._data[n]
            self._newData[index2] = self._data[n]
            self._newData[index3] = self._data[n]
            self._newData[index4] = self._data[n]
            self._newData[index5] = self._data[n]
            self._newData[index6] = self._data[n]
            self._newData[index7] = self._data[n]
            if n % updateNum == 0:
                progressFunc(value)
                value = value+1
        return self._newData


That is my function.  I have narrowed the problem down to where I assign 
values to index 0 through 7. 
If I just assign those values to some constant ie. 0 it doesn't eat up my 
memory.  (shown below)

index0 = 0
index1 =0
index2 = 0 ....  #doing this works

Does anyone have any idea why I would be "leaking" memory?? The above 
algorithm works fine with smaller data sets and even does what I want it 
to do but anything large and it uses up all the memory and dies.  Thank 
you for any advice. ~Ed


--=_alternative 005B759405256D5C_=
Content-Type: text/html; charset="us-ascii"


<br><font size=2 face="sans-serif">Previously I was having a memory problem and it was pointed out that the range function is quite the memory hog and to use xrange instead. &nbsp;Unfortunately this didn't solve the problem (though it did fix a problem that I would have probably encountered later with larger data sets) &nbsp;I don't like just pasting code into my email but I'm afraid it's the only way I can explain the problem. &nbsp;So here it goes. &nbsp;When I start up the program and it loads the data set it uses up a fixed amount of memory. &nbsp;As the subvoxelize function shown below continues to run (takes about 5 minutes before crashing) the memory usage just keeps increasing at a constant rate until I run out of memory. &nbsp;</font>
<br>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; def subvoxelize(self, progressFunc=None):</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; value = 0</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; updateNum = self._numVoxelsOrig/100</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; for n in xrange(self._numVoxelsOrig): &nbsp; #self._numVoxelsOrig has a value of around 20 million</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x, y, z = self.to3d(n) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#not causing any problems with memory</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x2, y2, z2 = x*2, y*2, z*2 &nbsp;</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index0 = x2 &nbsp; &nbsp; &nbsp;+ y2*self._newXsize &nbsp; &nbsp; + z2 * (self._newXY) &nbsp; #here is where the problem is and with the subsequent assignments</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index1 = x2+1 + y2*self._newXsize &nbsp; &nbsp; + z2 * (self._newXY)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index2 = x2 &nbsp; &nbsp; &nbsp;+ (y2+1)*self._newXsize + z2 * (self._newXY)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index3 = x2+1 + (y2+1)*self._newXsize + z2 * (self._newXY)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index4 = x2 &nbsp; &nbsp; &nbsp;+ y2*self._newXsize &nbsp; &nbsp; + (z2+1) * (self._newXY)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index5 = x2+1 + y2*self._newXsize &nbsp; &nbsp; + (z2+1) * (self._newXY)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index6 = x2 &nbsp; &nbsp; &nbsp;+ (y2+1)*self._newXsize + (z2+1) * (self._newXY)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index7 = x2+1 + (y2+1)*self._newXsize + (z2+1) * (self._newXY) &nbsp;#if I don't do these assignments and make each index go to a constant it doesn't leak memory</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index0] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index1] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index2] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index3] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index4] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index5] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index6] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self._newData[index7] = self._data[n]</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if n % updateNum == 0:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; progressFunc(value)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = value+1</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; return self._newData</font>
<br>
<br>
<br><font size=2 face="sans-serif">That is my function. &nbsp;I have narrowed the problem down to where I assign values to index 0 through 7. &nbsp;</font>
<br><font size=2 face="sans-serif">If I just assign those values to some constant ie. 0 it doesn't eat up my memory. &nbsp;(shown below)</font>
<br>
<br><font size=2 face="sans-serif">index0 = 0</font>
<br><font size=2 face="sans-serif">index1 =0</font>
<br><font size=2 face="sans-serif">index2 = 0 .... &nbsp;#doing this works</font>
<br>
<br><font size=2 face="sans-serif">Does anyone have any idea why I would be &quot;leaking&quot; memory?? The above algorithm works fine with smaller data sets and even does what I want it to do but anything large and it uses up all the memory and dies. &nbsp;Thank you for any advice. ~Ed</font>
<br>
<br>
--=_alternative 005B759405256D5C_=--