[Python-Dev] __del__ and tp_dealloc in the IO lib

Guido van Rossum guido at python.org
Fri Jan 23 03:42:25 CET 2009

On Thu, Jan 22, 2009 at 5:22 PM, Giovanni Bajo <rasky at develer.com> wrote:
> CPython will always use reference counting and thus have a simple and
> clear GC criteria that can be exploited to simplify the code.

Believe this at your own peril.

Once, CPython didn't have GC at all (apart from refcounting). Now it
does. There are GC techniques that delay DECREF operations until it's
more convenient. If someone finds a way to exploit that technique to
save 10% of execution time it would only be right to start using it.

You *can* assume that objects that are no longer referenced will
*eventually* be GC'ed, and that GC'ing a file means flushing its
buffer and closing its file descriptor. You *cannot* assume that
objects are *immediately* GC'ed. This is already not always true in
CPython for many different reasons, like objects involved in cycles,
weak references, or tracebacks saved with exceptions, or perhaps
profiling/debugging hooks. If we found a good reason to introduce file
objects into some kind of cycle or weak reference dict, I could see
file objects getting delayed reclamation even without changes in GC

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list