Destructor never called ???
aahz at pythoncraft.com
Fri Sep 20 06:33:32 CEST 2002
In article <4e8lou018f9uosl5p9mb0tt6691mfivamj at 4ax.com>,
Tim Roberts <timr at probo.com> wrote:
>aahz at pythoncraft.com (Aahz) wrote:
>>In article <tp70ou0r0j11as6enhpsaqul4oqa3mlu6t at 4ax.com>,
>>Tim Roberts <timr at probo.com> wrote:
>>>However, Python is a garbage-collected system. Unlike in COM, an object is
>>>NOT destroyed as soon as its reference count goes to 0. Your object will
>>>only be destroyed if the garbage collector happens to run, and decides that
>>>it might be a convenient time to actually free up the space your object
>>Wrong. CPython uses reference counting backed by GC.
>Well, then, what was all the fuss about deterministic desctructors in the
>newsgroup last year or so? Has this changed, or am I just remembering this
There are several different issues. First of all, __del__ does not get
called if an object is destroyed by GC (GC gets used to clean up cyclic
garbage). Secondly, Jython does not use refcounting; it's pure GC, just
like Java. Therefore, if you want to write portable applications, you
should not rely on refcounting.
Finally, there's a stylistic issue in programming. Some people believe
that the "explicit is better than implicit" design goal requires
cleaning up after oneself. Actually, it's unfair to say that it's
"just" a stylistic issue -- it's certainly possible that calling out to
libraries requires that one issue explicit close() calls.
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Project Vote Smart: http://www.vote-smart.org/
More information about the Python-list