[ python-Bugs-1273504 ] Cycle containing a Set is not GC'd [leak]
SourceForge.net
noreply at sourceforge.net
Fri Aug 26 05:53:36 CEST 2005
Bugs item #1273504, was opened at 2005-08-25 17:20
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1273504&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: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Duplicate
Priority: 5
Submitted By: Pierre-Frédéric Caillaud (peufeu)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Cycle containing a Set is not GC'd [leak]
Initial Comment:
Summary
-------------------------
Python's GC detects cycles except if there is a set somewhere in the
cycle.
For instance.
>>> class Survivor( object ):
... def __init__( self ):
... self.s = set( (self,) )
...
>>> Survivor()
<__main__.Survivor object at 0xb7ce68ac>
>>> Survivor()
<__main__.Survivor object at 0xb79b0b0c>
>>> len( [ x for x in gc.get_objects() if isinstance( x, Survivor ) ] )
2
>>> gc.collect()
0
>>> gc.collect()
0
>>> len( [ x for x in gc.get_objects() if isinstance( x, Survivor ) ] )
2
>>> [ x for x in gc.get_objects() if isinstance( x, Survivor ) ]
[<__main__.Survivor object at 0xb7ce68ac>, <__main__.Survivor
object at 0xb79b0b0c>]
So, the Survivors survive gc.collect() !
See more complete test case below.
System infos
-------------------------
$ python
Python 2.4.1 (#1, May 14 2005, 18:44:52)
[GCC 3.3.5 (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3, pie-8.7.7.1)] on linux2
>>> import gc
>>> gc.get_threshold()
(700, 10, 10)
OK, gc is compiled in, proceed...
Test Case
-------------------------
The attached program creates a new-style class and an old-style class
(of appropriate names). We create instances of these objects, each
having only a member, being a set, or a dict, or a list. Then we create
a cycle by putting the object itself inside this list, dict, or set, collect()
a few times ; cycles involving lists and dicts are gone, cycles involving
sets stay.
This was to check if it had anything to do with something else than
sets ; apparently sets are the cause.
The source is self-explanatory.
Enjoy !
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-25 22:53
Message:
Logged In: YES
user_id=80475
This is a duplicate report.
Was fixed for 2.4.2. which should be out in September.
----------------------------------------------------------------------
Comment By: Pierre-Frédéric Caillaud (peufeu)
Date: 2005-08-25 18:09
Message:
Logged In: YES
user_id=587274
Looks like it's a dupe. I did not see it in the release notes. Is it fixed in a
recently released version ? It's a rather annoying bug, caught a server
process hogging all the RAM and swap today because of this one.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2005-08-25 17:25
Message:
Logged In: YES
user_id=31435
Assigned to Raymond. Is this a duplicate of
http://www.python.org/sf/1200018
?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1273504&group_id=5470
More information about the Python-bugs-list
mailing list