Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68300 > unrolled thread

Re: What does gc.get_objects() return?

Started byChris Angelico <rosuav@gmail.com>
First post2014-03-13 08:44 +1100
Last post2014-03-13 08:44 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: What does gc.get_objects() return? Chris Angelico <rosuav@gmail.com> - 2014-03-13 08:44 +1100

#68300 — Re: What does gc.get_objects() return?

FromChris Angelico <rosuav@gmail.com>
Date2014-03-13 08:44 +1100
SubjectRe: What does gc.get_objects() return?
Message-ID<mailman.8106.1394660698.18130.python-list@python.org>
On Thu, Mar 13, 2014 at 8:28 AM, Jurko Gospodnetić
<jurko.gospodnetic@pke.hr> wrote:
>   So gc.collect() returns a list of all the objects GC is in charge of, and
> which instances are and are not tracked by the GC is, I guess, an
> interpreter implementation detail.

I assume you don't mean collect() there, as that returns the amount of
garbage that it just collected :)

It's not strictly an implementation detail, beyond that there are
certain optimizations. For instance...

>   For CPython 3.4 I guess strings and other atomic types such as ints are
> not, as well as raw object() instances. Custom class instances on the other
> hand seem to be under GC control.

... strings and ints should never be listed, and custom objects should
always be listed, but I'd say the non-tracking of object() would be an
implementation-specific optimization. Definitely the non-tracking of a
dict of nothing but atomic keys and values would be that.

The concept is that the GC tracks (in that sense; everything in
CPython is refcounted, but that's not what these functions look at)
anything that could be a part of a reference cycle. That's all it
concerns itself with, so something that can't have references to
arbitrary objects can't possibly be worth tracking. Interestingly, a
tuple of integers is tracked:

>>> a=1,2,3
>>> gc.is_tracked(a)
True

So not all optimizations are done that could be done.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web