does python have useless destructors?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri Jun 18 05:04:38 EDT 2004


On Fri, 18 Jun 2004 01:43:59 -0700, David Turner wrote:

> The most obvious way in which RAII can be enabled is by introducing
> defined reference-counting semantics for objects with __del__.  I
> can't think of another way of doing it off-hand, but there must be
> others (if reference counting has unacceptably high overhead).

The variables which hold these objects must be distinguished.
Not just the objects themselves.

> One possibility is to introduce scoped objects, analogous to auto or
> stack-allocated objects.  It would be illegal to pass a reference to
> these outside of a given scope, and they would have __del__ (or
> another method) called when the scope ends.

What would happen when you store a reference to such object in another
object? Depending on the answer, it's either severely limited (you can
introduce no abstractions which deal with files somewhere inside), or as
inefficient as reference counting.

The only way is to somehow distinguish variables for which objects they
point to should be finalized, from plain variables. Not objects but
variables. try...finally and with are examples of that.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/




More information about the Python-list mailing list