[Python-bugs-list] [ python-Bugs-543148 ] Memory leak with stackframes + inspect

noreply@sourceforge.net noreply@sourceforge.net
Fri, 12 Apr 2002 12:16:32 -0700


Bugs item #543148, was opened at 2002-04-12 14:48
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=543148&group_id=5470

Category: None
Group: Python 2.1.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Bernhard Herzog (bernhard)
>Assigned to: Neil Schemenauer (nascheme)
Summary: Memory leak with stackframes + inspect

Initial Comment:
The following program leaks memory on Python 2.1.3:

import inspect

def leak():
    frame = inspect.currentframe()

while 1:
    leak()

(On Linux at least the process size grows *very*
quickly!)

System:
Python 2.1.3 (#1, Apr 12 2002, 20:09:56) 
[GCC 2.95.4 20011006 (Debian prerelease)] on linux2


It has no memory problems with Python 2.2.

Workaround: del frame in leak.
The docs at least should mention this.


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

>Comment By: Tim Peters (tim_one)
Date: 2002-04-12 15:16

Message:
Logged In: YES 
user_id=31435

Yes, when you create a cyclic structure involving frames in 
2.1, it plain leaks -- frames aren't looked at by the 
cyclic garbage detector in 2.1.  Frames were added to 
cyclic gc collection in 2.2.

However, it sure looks to me like this program *still* 
leaks in 2.2 (and current CVS), just a lot slower (I've 
watched it grow to over 30MB on Windows, with no sign of 
ever stopping).  But if I call gc.collect() periodically in 
the "while 1:" (every 100th time) it doesn't leak at all 
(and stays at about 2MB).  Assigning to Neal in the hopes 
that it will be instantly obvious to him why gc isn't 
happening without being forced -- or perhaps why gc is 
happening but is ineffective in this case.  Maybe the 
frameobject free_list is interfering?

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

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