__del__ problem - would adopting Garbage Collection fix this?

Michael Hudson mwh21 at cam.ac.uk
Wed Apr 19 17:15:23 EDT 2000


"Warren Postma" <embed at geocities.com> writes:

> My questions:
> 
> 1. Shouldn't freeing modules in Py_Finalize be in the reverse order
> of the way in which the modules were created?  Could a
> module-destruction order be explicitly maintained by the system?

It's not clear that that would help; I'd bet I could come up with a
counter example if I was feeling twisted enough.

> 2. Is this convincing proof, or not, that Garbage Collection would
> be a Good Thing.

I don't think so.  You still have to destroy things; true gc might
help I suppose, but I'm fairly sure it doesn't solve the problem
completely.

> Is JPython immune to these bizarre behaviours?

Well, I don;t think JPython implements __del__ methods, so yes, but
not in a helpful way...

> 3. What about adding a __finalize__ method to objects.  Python could
> then finalize all objects first, and then delete them, and the rule
> is you ONLY EVER USE __del__ when you Absolutely Have to, and with
> some known issues (such as this). In other words, all objects are
> finalized in Py_Finalize, then destroyed. When an object is deleted
> with del(obj), it is finalized first, then freed.

But this would help the problem; if a file object has a finalize
method, and some other object wants to write to one of these file
objects in *its* finalize method... what you need is some way of
spelling "finalize me before him", and that's what we have already
(it's just a bizarre way of spelling it).

> 4. Until such point as there is a __finalize__, I am actually going
> to explicitly call a finalization method, then delete objects. Side
> effects on Destructors can arguably be a Bad Thing.

Surely a side-effect-free destructor is one of the most pointless
concepts possible?

I-think-the-reason-I-don't-know-a-neat-solution-is-because
-there-isn't-one-ly y'rs
M.

-- 
39. Re graphics:  A picture is worth 10K  words - but only those 
    to describe the picture. Hardly any sets of 10K words can be 
    adequately described with pictures.
     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html



More information about the Python-list mailing list