[ python-Bugs-808596 ] apparently leaking snippet

SourceForge.net noreply at sourceforge.net
Mon Dec 19 04:36:25 CET 2005


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

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 2
Submitted By: Michael Hudson (mwh)
Assigned to: Nobody/Anonymous (nobody)
Summary: apparently 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: Neal Norwitz (nnorwitz)
Date: 2005-12-18 19:36

Message:
Logged In: YES 
user_id=33168

I just tested this on 2.5a and there were no ref leaks, so
closing again.

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

Comment By: Michael Hudson (mwh)
Date: 2004-08-09 06:46

Message:
Logged In: YES 
user_id=6656

Reopening, as it turned out interning filenames did do some
good.

Lowering priority as it isn't a real leak.

It's still kinda annoying, though.

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

Comment By: Michael Hudson (mwh)
Date: 2004-08-03 03:25

Message:
Logged In: YES 
user_id=6656

Done, in Python/compile.c revision 2.312.

test_pkgimport turned out to be something else 
(sys.path_importer_cache), so I feel no need to try and be clever 
with dummy's refcounting today.

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-08-02 08:11

Message:
Logged In: YES 
user_id=80475

Not interning the filename seems cleanest.  Like you, I do
not expect that interning provided any real benefit here.

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

Comment By: Michael Hudson (mwh)
Date: 2004-08-02 05: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