Python vs Java garbage collection?

Robert Oschler Oschler at earthlink.net
Mon Dec 23 19:00:53 EST 2002


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3E071DB7.DE9FA7D7 at engcorp.com...
> I offer this merely as representative of one of the scenarios that
> could happen if one fails to close files explicitly.
>
> Admittedly this is not a typical sequence, but the point is, you cannot
> *always* rely on the CPython finalization behaviour even in CPython, so
> why waste time guessing when you can, and when you can't?
>
>

Wait a minute, didn't Martin just say in a previous post that you can rely
on CPython to call __del__ when reference counts reach 0?  How could Python
"forget" to decrement a reference count, even if an exception occurs in a
finally block or anywhere else for that matter?  If the reference holder is
a stack object (function local variable), then when the stack is unwound the
reference count would get decremented, no matter how the funciton exited
(exception, normal return, etc).  If the reference is in a container, then
the reference count would get decremented when the container is wiped or the
object holding the reference is deleted from the container.  Or am I reading
too much of C++ behavior into Python's reference count management?

Did I miss something?

thx





More information about the Python-list mailing list