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


Groups > comp.lang.python > #68292

What does gc.get_objects() return?

From Jurko Gospodnetić <jurko.gospodnetic@pke.hr>
Subject What does gc.get_objects() return?
Date 2014-03-12 20:34 +0100
Organization PKE sistemi d.o.o.
Newsgroups comp.lang.python
Message-ID <mailman.8098.1394652868.18130.python-list@python.org> (permalink)

Show all headers | View raw


   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 
them? Which does it return? Which it does not?

   For example (done using CPython 3.4 interactive interpreter) here it 
does not contain an object I know exists:

> >>> a = object()
> >>> a in gc.get_objects()
> False

   but here it does:

> >>> class Foo: pass
> ...
> >>> a = Foo()
> >>> a in gc.get_objects()
> True

   It also does not seem to contain string objects. At first I thought 
that perhaps interned strings were not placed under GC control, so I 
tested this:

> >>> a = "asdkjfhk23498237$&(*$&*($ksjdhfkjsd"
> >>> b = "asdkjfhk23498237$&(*$&*($ksjdhfkjsd"
> >>> a is b
> False
> >>> a in gc.get_objects()
> False
> >>> b in gc.get_objects()
> False

   Which shows that non-interned scripts such as these are not getting 
listed in gc.get_objects() either. :-s

   Many thanks.

   Best regards,
     Jurko Gospodnetić

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


Thread

What does gc.get_objects() return? Jurko Gospodnetić <jurko.gospodnetic@pke.hr> - 2014-03-12 20:34 +0100

csiph-web