Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'cpython': 0.05; 'self.data': 0.09; 'cc:addr:python-list': 0.11; 'cc:name:python list': 0.16; 'foo()': 0.16; 'object()': 0.16; 'other)': 0.16; 'pypy.': 0.16; 'typeerror:': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'java': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'them?': 0.31; 'file': 0.32; 'class': 0.32; '(most': 0.33; 'could': 0.34; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'skip:" 50': 0.36; 'subject:?': 0.36; 'detail': 0.37; 'list': 0.37; 'pm,': 0.38; 'recent': 0.39; 'explain': 0.39; 'does': 0.39; '12,': 0.39; 'applicable': 0.60; 'more': 0.64; 'here': 0.66; 'mar': 0.68; '3.4': 0.84; 'skip:/ 30': 0.84; 'subject:skip:g 10': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=RuAH7RLYmJL/T+0Z2XRD4u7gKbrhp0Qvu6GmfDcHX20=; b=KwcSRiyQbNviaHqu6Nf4ekuIHxMqMRrHzBn9zaAAzabHMAVnvICPBGqX3aiELe3fQw Tc4SHij86XbkFKk3sIR42uoTLCQWpnuEhAsvAm3ZzsXRfh8kGpsGo3Zjt8Wm8S2XRdSk +bRSNShX8Pp6oPIwIJydaSiRuzIHORKHVN3kKAeGumceAYQKzdEkSqU/7cPZmx5t9HAK F5X3mFZudIaYjiZ/TOjn3JIBCcA1GqpkBlrEQn71NuJZT4YVA0HnG31vM2qLEzHi5BHK FOvxFdD0gMglaUzQw/fBatVyyKC1Ll8GYEsvj1k9/uyj36hNMcWw5hEqGcKEEh1prwm1 B8Bw== MIME-Version: 1.0 X-Received: by 10.236.90.12 with SMTP id d12mr4801064yhf.120.1394654007592; Wed, 12 Mar 2014 12:53:27 -0700 (PDT) In-Reply-To: References: Date: Wed, 12 Mar 2014 12:53:27 -0700 Subject: Re: What does gc.get_objects() return? From: Dan Stromberg To: =?UTF-8?Q?Jurko_Gospodneti=C4=87?= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Python List 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: 72 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394654016 news.xs4all.nl 2960 [2001:888:2000:d::a6]:43560 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68295 On Wed, Mar 12, 2014 at 12:34 PM, Jurko Gospodneti=C4=87 wrote: > Hi all. > > 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 th= em? > Which does it return? Which it does not? > > For example (done using CPython 3.4 interactive interpreter) here it do= es > not contain an object I know exists: > >> >>> a =3D object() >> >>> a in gc.get_objects() >> False > > > but here it does: > >> >>> class Foo: pass >> ... >> >>> a =3D Foo() >> >>> a in gc.get_objects() >> True I don't know why some objects aren't showing up in get_objects, but here's a quick note to say it's not just 3.4: $ ./pythons 'import gc; var=3D"data"; print(var in gc.get_objects())' /usr/local/cpython-2.4/bin/python [6600 refs] False /usr/local/cpython-2.5/bin/python False [7536 refs] /usr/local/cpython-2.6/bin/python False [15233 refs] /usr/local/cpython-2.7/bin/python False [18526 refs] /usr/local/cpython-3.0/bin/python Traceback (most recent call last): File "", line 1, in File "/usr/local/cpython-3.0/lib/python3.0/_weakrefset.py", line 121, in __eq__ return self.data =3D=3D set(ref(item) for item in other) File "/usr/local/cpython-3.0/lib/python3.0/_weakrefset.py", line 121, in return self.data =3D=3D set(ref(item) for item in other) TypeError: cannot create weak reference to 'str' object [34510 refs] /usr/local/cpython-3.1/bin/python False [37270 refs] /usr/local/cpython-3.2/bin/python False [37700 refs] /usr/local/cpython-3.3/bin/python False [42662 refs] /usr/local/cpython-3.4/bin/python False /usr/local/pypy-2.2/bin/pypy True /usr/local/jython-2.7b1/bin/jython Traceback (most recent call last): File "", line 1, in NotImplementedError: not applicable to Java GC Interesting that it is present in Pypy.