destructors -- when are they called?
effbot at telia.com
Tue May 30 10:41:55 CEST 2000
> > This should be quite obvious from the Py_DECREF macro - it explicitely
> > calls the delete function when the ref count hits zero. In the current
> > implementation, it is indeed guaranteed (even though the language spec
> > specifically refuses to guarantee it)
> Actually both of these are interesting data points. So what
> you're saying is that code functionality which relies on a
> 0 object reference calling the destructor will work 100% of
> the time now, but might break in the future.
don't confuse the CPython implementation with the language.
in the current CPython implementation, this will always work.
I'm pretty sure it will work throughout the entire 1.X series
(changing it would simply break too much existing code).
but the language specification deals with things on the Python
level, and Python doesn't really require reference counting.
so your code may not work under *other* implementations
(including future C implementations of future Python versions,
if that's a problem, you better stick to pure Python code ;-)
More information about the Python-list