[ python-Bugs-808596 ] leaking snippet

SourceForge.net noreply at sourceforge.net
Mon Aug 2 14:56:08 CEST 2004


Bugs item #808596, was opened at 2003-09-18 15:48
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=808596&group_id=5470

Category: None
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Hudson (mwh)
Assigned to: Nobody/Anonymous (nobody)
Summary: leaking snippet

Initial Comment:
Raymond Hettinger found that the following:

 fd, fname = tempfile.mkstemp()
 execfile(fname)

leaks a reference.  TrackRefs sez it's a string. 
Haven't dug any further.

----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2004-08-02 13:56

Message:
Logged In: YES 
user_id=6656

I've finally worked out what's going on here.

It's because compiling the file interns the name of the file being 
compiled.  Now that interned strings are mortal, this isn't a big 
deal, but it still results in a string being added to and removed 
from the interned strings dictionary with net result (almost all of 
the time) of incrementing the refcount on 'dummy' by one.  Once 
in every thousand or so iterations this results in the interned 
string dictionary being resized and throwing all the references to 
dummy away, so this isn't a 'real' leak.

OTOH, I'd still like to do something about this (as is, test_pkg 
appears to leak 10 references per run because of this).  The 
simplest thing would be to just plain not intern the filename during 
compilation (I find it hard to believe that it's of any real 
benefit). The more invasive solution would be to not do 
refcounting on dummy (assuming that's even possible) which is a 
scarier change, but would stop similar problems with other tests (I 
have a feeling that test_pkgimport appears to be leaking 
references because of a different incarnation of the same 
problem).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=808596&group_id=5470


More information about the Python-bugs-list mailing list