[Python-Dev] Garbage collecting closures
Jeremy Hylton
jeremy@zope.com
14 Apr 2003 10:52:42 -0400
On Mon, 2003-04-14 at 10:34, Paul Prescod wrote:
> I don't know what the solution is, but it seems quite serious to me that
> there is another special case to remember when reasoning about when
> destructors get called. Roughly, Python's cleanup model is "things get
> destroyed when nothing refers to them." Then, that gets clarified to
> "unless they have reference cycles, in which case they may get destroyed
> arbitrarily later" and now "or they are used in a function containing
> another function, which will cause a circular reference involving all
> local variables."
The details of when finalizers are called is an implementation detail
rather than a language property. You should add to your list of
worries: An object is not finalized when it is reachable from a cycle of
objects involving finalizers. They don't get destroyed at all.
Finalizers seem useful in general, but I would still worry about any
specific program that managed critical resources using finalizers.
Jeremy