Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.061 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'python,': 0.02; 'cpython': 0.05; 'subject:Python': 0.06; 'lst': 0.09; 'python': 0.11; 'cleaned': 0.16; 'subject: \n ': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'creating': 0.23; 'necessary.': 0.24; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'message- id:@mail.gmail.com': 0.30; 'chase': 0.31; 'advice': 0.35; 'except': 0.35; 'objects': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'subject:data': 0.36; 'subject:?': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'major': 0.40; 'manually': 0.60; 'subject:Can': 0.60; 'break': 0.61; "you're": 0.61; 'such': 0.63; 'more': 0.64; 'believe': 0.68; 'containing': 0.69; 'guaranteed': 0.75; 'subject:this': 0.83; '2015': 0.84; '3.4': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=xAE0ttSGLpDK/SCDnRaqf9EOut+gOy250ihjkgCyhio=; b=Swttbic30sQ1QK/y7XRPXqI7iRPBC8pr/PzjdhIFw31cEm/4IhlYNyAT6lIbWqod0h OBSzs8RtC0bGfl/wRjT97VD7f4yV0SxKDDJZcY1oNdtmVLbadgCoQPGpFTnDf7mdjjqW Fx508OtfC4FARRxzW+ewnOA1T+cwZHPQrG78pTs6BRTjBRBfJp6BFk//fZy4l+gnpLKX NabGnt35sQm7+i5lZjDfz+IC1fmMHDEJH/7lSuPXSEko3M+UcpzzjKYvgDBGQ8pmRfmD uAUm4+njPjOOkuAn6QdGokzXg+bcEOfslmVVrAbsnnhtfFxpEgIaOSwvFofip75Yeak2 4dqA== X-Received: by 10.107.136.89 with SMTP id k86mr19907145iod.63.1430628221645; Sat, 02 May 2015 21:43:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20150502151723.3a36e33b@bigbox.christie.dr> References: <387ac520-9da3-411a-a3b8-b326e1e8a2c0@googlegroups.com> <20150502151723.3a36e33b@bigbox.christie.dr> From: Ian Kelly Date: Sat, 2 May 2015 22:43:01 -0600 Subject: Re: Inner workings of this Python feature: Can a Python data structure reference itself? To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430628229 news.xs4all.nl 2880 [2001:888:2000:d::a6]:39828 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89827 On Sat, May 2, 2015 at 2:17 PM, Tim Chase wrote: > If you know that you're creating such cyclical structures, it's best > to manually unlink them before freeing them: > > lst = [] > lst.append(lst) # create the cycle > lst[:] = [] # break the cycle > # or lst.remove(lst) # though this takes more care > del lst In general, this shouldn't be necessary. I believe that reference cycles are guaranteed to be cleaned up in all major implementations of Python, except that in CPython prior to version 3.4 reference cycles containing objects with finalizers would not be collected. So the better advice would be "don't use finalizers in reference cycles if you need compatibility with Python 3.3 or earlier."