memory leak?

Bjorn Pettersen BPettersen at NAREX.com
Sun Aug 3 20:09:47 EDT 2003


> From: Trevor Perrin [mailto:trevp at trevp.net] 
> 
> "Bjorn Pettersen" <BPettersen at NAREX.com> wrote in message 
> news:<mailman.1059908345.3987.python-list at python.org>...
> > > From: Trevor Perrin [mailto:trevp at trevp.net] 
> > > 
> > > Every time I run the below function from the interpreter, 
> > > python.exe's
> > > memory usage increases by 5 Megs and stays at this higher level
> > > (python 2.3b2 on WinXP).  I tried to isolate this to something
> > > simpler, but wasn't successful.
> > > 
> > > Is this a memory leak, or is there another explanation?
> > [...]
> 
> Hi Bjorn,
> 
> > Have your tried 2.3 final,
> 
> I just did, same thing.

Good -- usually, fixing existing bugs have much higher priority than
backporting fixed bugs.

> > how are you determining there is a memory
> > leak (which tools),
> 
> Windows Task Manager display process memory use.

<DrPhil>..and how is that working out for you?<DrPhil> *grin*. It's
usually easy to determine if something is a leak using TM, by putting
the leaking code in a loop:

   while 1:
      test()

If memory keeps going up without bounds, there is a better probability
that it's a leak (however it could also be garbage waiting for the gc
collector), if it doesn't you're probably seeing the normal effects of
malloc/free rarely returning memory to the OS, global state, etc. This
won't give any info about where the leak is, so you'd either have to get
a program that can analyze this (e.g. Rational's Purify), or turn on the
memory debug aids availabe in debug builds of Python. In any case, you
should probably file a bugreport at sourceforge,
http://sourceforge.net/tracker/?atid=105470&group_id=5470&func=browse, I
forget if you have to register to file a new bug..

> > what steps did you take that weren't successful, 
> 
> I tried calling array.array() and random.randrange() the same number
> of times in a loop, but the behavior didn't reproduce.
> 
> > did you try without using "import *", how about loading it as a 
> > module and then deleting the module (i.e. have you inadvertenly 
> > created an object that is still live)?
> 
> I tried that, and also using xrange().  Below is a transcript from the
> interpreter, after running it python.exe had increased memory use from
> ~3 MB to ~21 MB.  Maybe there's an innocuous explanation, I'm no
> python expert, I'm just curious:

Thanks. Knowing what you did kept me from repeating it, knowing you'd
tried the standard approaches without success made it interesting enough
to take it for a spin :-)

At first glance it seems suspicious (but I'm not very familiar with
array, nor the new implementation of random), so go ahead and file it.
E.g.: "The following progam leaks indefinetly":

import array
import random

def test():
    randrange = random.randrange
    range_64 = range(64)
    for x in xrange(10000):
        b = array.array("B", [randrange(0,256) for unused in range_64])

while 1:
    test()
  
-- bjorn





More information about the Python-list mailing list