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


Groups > comp.lang.python > #68439

Re: What does gc.get_objects() return?

From Antoine Pitrou <solipsis@pitrou.net>
Subject Re: What does gc.get_objects() return?
Date 2014-03-17 17:18 +0000
References <lfqcr8$249$1@ger.gmane.org> <5320BD3F.5030509@mrabarnett.plus.com> <lfqjgu$kug$1@ger.gmane.org> <CAPTjJmqdKZ6qDQ+PZAdxVF-hKN=txKh35ga_C451C2z_hpZZAA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.8206.1395076808.18130.python-list@python.org> (permalink)

Show all headers | View raw


Chris Angelico <rosuav <at> gmail.com> writes:
> 
> 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.

These are all implementation details, tied to the fact that the primary
object reclaim mechanism in CPython is reference counting. Other 
implementations may use a full GC and gc.get_objects() may then also
return strings and other "atomic" objects (but the implementation may
also elicit to hack get_objects() in order to closely mimick CPython).

All in all, though, gc.get_objects() is an expensive function call (it
will walk the entire graph of objects tracked by the GC, which can be very
large in non-trivial applications), so it's really only useful for
debugging (and, I'd add, for low-level debugging). In most situations,
gc.get_objects() is certainly the wrong tool to use.

Regards

Antoine.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: What does gc.get_objects() return? Antoine Pitrou <solipsis@pitrou.net> - 2014-03-17 17:18 +0000

csiph-web