Python vs Java garbage collection?

Robert Oschler Oschler at earthlink.net
Mon Dec 23 17:26:32 EST 2002


"Martin v. Löwis" <martin at v.loewis.de> wrote in message
news:au7fv7$98i$02$1 at news.t-online.com...
>
> However, I'm still curious as to what precisely the '"destructors
> please" issue' is that you have been pushing for quite some time, and
> what precisely it would mean to add destructors to Python and Java. I'm
> speaking as a language designer here, so I'm not too interested in how
> you would use the facility until I know what the facility is.
>

Martin,

Not being a language designer myself, and knowing almost nothing about how
either Java and Python track their reference counts, I hope I don't sound
like I'm making too simple a message by describing below what I mean by
having destructors in Python.  But here's the holy grail:

I'd like there to be a method of an object that is called the instant an
object's reference count drops to 0 and not when the garbage collector gets
around to cleaning up.  This method is guaranteed to be called when an
object's reference count drops to 0, and at the exact moment that occurs (or
reasonably close).  The implied assumption is also that all object reference
counts drop to 0 on program termination, if not, then that additional
behavior too, so that program global objects could be counted on to have
their destructors called at some time.

If garbage collected languages would have trouble adopting this behavior,
due to the treachery of releasing an object's memory outside of the garbage
collector's normal "schedule", then I would like to formally decouple the
sentiment attached to destructors that involves memory management.  I can't
speak for the other's here that also have indicated that they want to see
destructor's, but I'm actually far more concerned with automatic resource
cleanup rather than memory reclamation (releasing database file and
record/locks, releasing a socket, a kernel object, etc.).  If all the
Python:Java destructor did was simply guarantee that there  was an object
method that was called automatically when an object's reference count
dropped to 0, and didn't release any memory belonging to the terminating
object at all, leaving that to the gc to do it when it normally does, I'd be
extremely happy.

thx





More information about the Python-list mailing list