Bugs item #1273504, was opened at 2005-08-25 18:20 Message generated for change (Comment added) made by tim_one 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: Open Resolution: None 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: Tim Peters (tim_one) Date: 2005-08-25 18: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com