does python have useless destructors?

Donn Cave donn at u.washington.edu
Mon Jun 14 18:42:54 CEST 2004


In article <Xns95089FFA7C71Fduncanrcpcouk at 127.0.0.1>,
 Duncan Booth <me at privacy.net> wrote:

> "Donn Cave" <donn at drizzle.com> wrote in news:1087052078.511051 at yasure:
> 
> > Er, Python guarantees that the object will almost always be destroyed?
> > What the heck does that mean?
> 
> It means the same as it does in other systems with garbage collection (such 
> as Java or .Net). Your object will be destroyed when the garbage collector 
> determines that it is unreachable. The 'almost always' is because even with 
> C Python's reference counting where when your program exits the system 
> attempts to free all the objects, if you start deliberately trying to 
> prevent it freeing everything it will give up.

Well, I think more could be said about that, and has been in this
thread.  My point was only that `guarantee that ... almost always'
adds up to nonsense.  Sorry I didn't spell that out.

> >| Guaranteeing that all resources will be released at a specific time
> >| has implications for performance, and finalisers are actually pretty
> >| rare in practice, so the usual solution is to compromise.
> > 
> > It isn't clear to me what it takes to guarantee immediate
> > finalization, so if it is to you, that might be worth spelling out a
> > little more. It doesn't cost anything in the ordinary case, I mean
> > with C Python's reference count storage model, if you get it, you get
> > it for free. 
> > 
> 
> You can guarantee immediate finalization for some objects by reference 
> counting, but reference counting is an overhead. Just because C Python is 
> paying that cost doesn't mean the cost isn't there.

As long as Python is doing it that way, it's academic whether
the cost is here or there.  But I see we're again talking about
a vacuous guarantee, as in `guarantee .. for some objects', kind
of a shift of subject.  If that's really what you were trying to
say, then thanks for clearing that up.  Otherwise, I'm confused.
Guaranteeing that all resources will be released at a specific time
would presumably mean solving the problems with cycles and __del__,
module shutdowns etc.  It looked like you knew of some likely
extra cost there.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list