[Python-Dev] Design question: call __del__ for cyclical garbage?

nascheme@enme.ucalgary.ca nascheme@enme.ucalgary.ca
Sun, 5 Mar 2000 17:27:54 -0700

On Fri, Mar 03, 2000 at 08:38:43PM -0500, Tim Peters wrote:
> So here's what I'd consider doing:  explicit is better than implicit, and in
> the face of ambiguity refuse the temptation to guess.

I like Marc's suggestion.  Here is my proposal:

Allow classes to have a new method, __cleanup__ or whatever you
want to call it.  When tp_clear is called for an instance, it
checks for this method.  If it exists, call it, otherwise delete
the container objects from the instance's dictionary.  When
collecting cycles, call tp_clear for instances first.

Its simple and allows the programmer to cleanly break cycles if
they insist on creating them and using __del__ methods.