Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'cpython': 0.05; 'versions.': 0.07; 'counting': 0.09; 'methods,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'references.': 0.09; 'jan': 0.12; '(excluding': 0.16; 'be:': 0.16; 'benefit.': 0.16; 'instances,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'seconds.': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'previously': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'instance,': 0.24; '---': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'wondering': 0.29; 'them?': 0.31; 'tuples': 0.31; 'probably': 0.32; 'checking': 0.33; 'could': 0.34; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'subject:?': 0.36; 'detail': 0.37; 'turn': 0.37; 'list': 0.37; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'explain': 0.39; 'does': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ago,': 0.61; 'break': 0.61; 'took': 0.61; 'received:173': 0.61; 'decided': 0.64; 'more': 0.64; 'kept': 0.65; 'details': 0.65; 'worth': 0.66; 'useful.': 0.68; 'subject': 0.69; 'therefore': 0.72; 'alone.': 0.84; 'answer:': 0.84; 'received:fios.verizon.net': 0.84; 'subject:skip:g 10': 0.84; 'whereas': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: What does gc.get_objects() return? Date: Wed, 12 Mar 2014 22:54:55 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394679328 news.xs4all.nl 2947 [2001:888:2000:d::a6]:34036 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68322 On 3/12/2014 3:34 PM, Jurko Gospodneti=C4=87 wrote: > I was wondering if someone could explain gc.get_objects() in a bit > more detail to me. > > Does it return a list of 'all objects known to Python'? Only some of= > them? Which does it return? Which it does not? This took about 10 seconds. >>> import gc >>> help(gc.get_objects) Help on built-in function get_objects in module gc: get_objects(...) get_objects() -> [...] Return a list of objects tracked by the collector (excluding the=20 list returned). --- Now, what object does gc track? CPython answer: objects that could be=20 involved in and kept alive by reverence cycles and therefore not deleted = when not needed by reference counting alone. Object instances, numbers,=20 and strings cannot be involved in reference cycles, as there are no user = settable references. Tuples can be: a =3D [] b =3D (a,) a[0] =3D b A tuple of, for instance, ints would not need to be tracked, but if it=20 is, someone probably decided that the cost of checking is not worth the=20 benefit. Details are subject to change with versions. In 3.4, gc can=20 break cycles of objects with delete methods, whereas they previously=20 waiting until program shutdown. Some year ago, I remember a suggestion=20 to turn off gc while creating lots of tuples that did not need to be=20 tracked, but I do not know if that is still useful. --=20 Terry Jan Reedy