does python have useless destructors?
Duncan Booth
me at privacy.net
Mon Jun 14 10:53:50 EDT 2004
"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.
I don't know of any systems either using reference counting or garbage
collections that actually guarantee that every object will be fully
finalised on program termination.
>
>| 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.
More information about the Python-list
mailing list