Whre is my object ??

Erik Max Francis max at alcyone.com
Wed Jun 4 05:22:28 CEST 2003

King Kuta wrote:

> I bet the base question is: Will my object be garbage-collected?

In the code example you showed, no.

> I mean once I delete it it is no more referenced, right?

Not necessarily.  In Python, the "del" statement (when applied to an
atomic variable name rather than an indexed name) merely eliminates that
name as a reference to the object.  But in Python, objects are garbaged
collected at some unspecified point after the last reference to them is
lost.  So because your object already has a reference to it elsewhere,
it is not going to be garbage collected.

> I can still manipulate it till it exist, because I have a pointer to
> its
> instance, but when (and most of all if) python checks for bindings it
> will
> find the object is not any more referenced to by any name.

Python is "safe" in this respect; the object won't be destroyed until
the last reference to it goes away.  Thus it's valid to use it if you
still have a reference to it; once there are no more references to it in
the interpreter, the object will be collected, but by definition you
won't have any references to it at that point anyway so no harm can be

   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ My reputation grows with every failure.
\__/  George Bernard Shaw

More information about the Python-list mailing list