Python 2.4.3 array memory leak

danmcleran at yahoo.com danmcleran at yahoo.com
Thu May 7 18:48:51 EDT 2009


On May 7, 4:41 pm, Terry Reedy <tjre... at udel.edu> wrote:
> danmcle... at yahoo.com wrote:
> > I am using the array module to instantiate many arrays in my
> > application. It seems like there is a memory leak in there somewhere.
> > Can anyone confim this and let me know what, if anything, I can do
> > about it? I am using Fedora Core 5 Linux:
>
> > import commands
> > import array
> > import itertools
> > import sys
>
> > from itertools import repeat
>
> > print '*** before ***'
> > print commands.getoutput('cat /proc/meminfo').split('\n')[1]
> > for i in range(100):
> >     a = array.array('I', repeat(0, int(2E6)))
> >     del a
> > print '*** after ***'
> > print commands.getoutput('cat /proc/meminfo').split('\n')[1]
>
> > Output:
> > *** before ***
> > MemFree:       1459772 kB
> > *** after ***
> > MemFree:       1457688 kB
>
> What happens if you remove the loop?  I would not be surprised if Python
> grabs the memory once, reuses it, and does not let go.  That is not a
> leak.  What happens if you put the after inside the loop?  Does mem
> usage steadily increase, and continue if you increase range to 1000,
> 10000?  That would be a leak.
>
> If there actually is a problem, try a later version of Python.

I'm not convinced there is a problem anymore. In my latest code, I
record the virtual mem allocated to my specific process and I do not
see it increasing. I would think that if I was leaking memory, I
should see a steady increase in virtual memory consumed by my process,
which I do not.

thanks



More information about the Python-list mailing list