Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'cpython': 0.05; 'subject:Python': 0.06; 'memory.': 0.07; 'cest': 0.09; 'correct,': 0.09; 'lst': 0.09; 'referenced': 0.09; 'references.': 0.09; 'python': 0.11; 'creates': 0.14; '22:06,': 0.16; 'collects': 0.16; 'cyclically': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'garbage': 0.16; 'itself,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'other,': 0.16; 'received:192.168.1.4': 0.16; 'subject: \n ': 0.16; 'wrote:': 0.18; '(where': 0.19; 'mechanism': 0.19; '>>>': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'circular': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'thus': 0.29; 'tim': 0.29; 'topic': 0.29; 'words': 0.29; '(optional)': 0.31; 'delayed': 0.31; 'url:05': 0.31; 'says': 0.33; 'url:python': 0.33; 'maybe': 0.34; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'scheme': 0.36; 'subject:data': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'subject:Can': 0.60; 'most': 0.60; 'url:3': 0.61; 'kind': 0.63; 'such': 0.63; 'soon': 0.63; 'become': 0.64; 'url:blogspot': 0.65; 'linked': 0.65; 'saturday': 0.68; 'containing': 0.69; 'guaranteed': 0.75; 'saw': 0.77; 'subject:this': 0.83; '2015': 0.84; 'url:datamodel': 0.84; 'url:reference': 0.84; 'drops': 0.91; 'hand,': 0.93 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=DZWZq5dW c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=SY9aFQKHIdAA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=7UEPrufcAAAA:8 a=8AHkEIZyAAAA:8 a=rEit6S6UCWle7Vgqu7AA:9 a=QEXdDO2ut3YA:10 a=ItF7quxhCH8A:10 a=a3VaZO-ygtUA:10 a=35aIS-mj8JEA:10 a=-FEs8UIgK8oA:10 a=NWVoK91CQyQA:10 X-AUTH: mrabarnett@:2500 Date: Sun, 03 May 2015 00:07:03 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Inner workings of this Python feature: Can a Python data structure reference itself? References: <387ac520-9da3-411a-a3b8-b326e1e8a2c0@googlegroups.com> <87a8xmn0yp.fsf@Equus.decebal.nl> In-Reply-To: <87a8xmn0yp.fsf@Equus.decebal.nl> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430608033 news.xs4all.nl 2848 [2001:888:2000:d::a6]:58517 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89812 On 2015-05-02 22:06, Cecil Westerhof wrote: > Op Saturday 2 May 2015 22:17 CEST schreef Tim Chase: > >> [dangit, had Control down when I hit and it sent >> prematurely] >> >> On 2015-05-02 13:02, vasudevram wrote: >>> http://jugad2.blogspot.in/2015/05/can-python-data-structure-reference.html >>> >>> https://docs.python.org/2/reference/datamodel.html >>> >>> and saw this excerpt: >>> >>> [ CPython implementation detail: CPython currently uses a >>> reference-counting scheme with (optional) delayed >>> detection of cyclically linked garbage, which collects >>> most objects as soon as they become unreachable, but is >>> not guaranteed to collect garbage containing circular >>> references. ] >>> >>> Not sure whether it is relevant to the topic at hand, >>> since, on the one hand, it uses the words "cyclically >>> linked", but on the other, it says "garbage collection". >> >> The gotcha happens in a case where you do something like this: >> >> lst = [] >> lst.append(lst) # create a cycle >> del lst >> >> This creates a cycle, then makes it unreachable, but the list is >> still referenced by itself, so the reference count never drops to >> zero (where it would get GC'd), and thus that item lingers around in >> memory. > > Maybe look at Java? If my memory is correct, the JVM gc reclaims those > kind of things also. > Python _does_ have a secondary mechanism for cleaning up such reference cycles using mark-and-sweep: https://docs.python.org/3/reference/datamodel.html