GC and finalizers [was: No destructor]

Paul Duffin pduffin at hursley.ibm.com
Fri Aug 25 05:07:58 EDT 2000


Neil Schemenauer wrote:
> 
> Paul Duffin <pduffin at hursley.ibm.com> wrote:
> >What happens if after calling the finalizer on an object which has
> >a zero reference count the object has a non-zero reference count ?
> 
> The same thing that happens in Python without GC.  The object
> remains alive but the finalizer will not be called again (at
> least in 2.0).
> 

What is the reasoning behind this ?

The __del__ function has done something to create an external reference to 
it, this means that it wants to be preserved. 

	Why does it want to do this ?
	How does it want to behave ?

One thought is that it could be used to create a cache of objects ready to
be used again. In this case it is very important that the object behaves
the same whether it is being used (freed) for the first time, the second 
time, or the 27th time. Which means that __del__ needs to be called 
everytime the object could be freed.

Maybe there is another Python idiom which is used for caching objects, or
maybe it is not necessary to cache objects I don't know.

I have more than a passing interest in this as I am trying to add mutable
objects to Tcl which brings with it the possibility of cycles and hence
a need for garbage collecting.



More information about the Python-list mailing list