[Tutor] Memory Leak?

Michael Langford mlangford.cs03 at gtalumni.org
Wed May 7 22:18:23 CEST 2008


You can always make a subclass of the classes you're thinking aren't being
garbage collected and put a print statement in their __del__ functions to
show you when they are. That will show you if/which objects aren't being
deleted.

Do you have any global variables?

           --Michael

On Wed, May 7, 2008 at 3:50 PM, Keith Suda-Cederquist <kdsudac at yahoo.com>
wrote:

> Hi,
>
> I'm doing some image processing using PIL and SciPy. Individual images are
> 2000x2000 pixels with each pixel being 16 bits, so a single image is around
> 7 MB in size.
>
> I've noticed that while my code is running the amount of memory being used
> (as reported by Windows Task Manager) by Python gradually increases.  It
> continues to increase if I re-run the same code again from within iPython
> (everytime I re-run the code the memory used increases by about 300 MB).  So
> after re-running the code several times (while debugging and/or developing)
> I will eventually get a memory exception (<type 'exceptions.MemoryError'>).
>
> Does this mean I've somehow created a memory leak?  From what I've read,
> in  Python 2.X creating a memory leak is a hard thing to do.  Perhaps I'm
> just doing a terrible job of coding and am constantly creating new things
> that take up memory???
>
> My basic code structure is below.  Anyone has any suggestions on how to
> improve the efficiency of my code or to debug this problem?
>
> Thank you in advance,
> Keith
>
> def function1(filename):
>     image1=im2array(filename)
>     #im2array is a function I wrote to open a tiff image as a scipy array
>     #average the 2000x2000 2d array into a single 2000x1 1d array
>     # perform some scaling on the 2000x1 1d array
>     #take the FFT of the 2000x1 1d array
>     result=[fftpeak, fftmaxamplitude]  #output is just two float values
>     return result
>
> filenames=['file1.tif','file2.tif',...]  #about 40 image filenames in this
> list
>
> results=[]
> for ind in xrange(0,len(filenames):
>     results.append(function1(filenames[ind]))
>
>
>
>
> ------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it
> now.<http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080507/82e2fbb4/attachment.htm>


More information about the Tutor mailing list