[Python-Dev] Garbage collecting closures
Mon, 14 Apr 2003 14:41:31 -0700
Guido van Rossum wrote:
> Paul, would finalizers have been run if you had included an explicit
> gc.collect() call?
> If so, I'd say that a sufficiently portable rule is that you can't
> trust finalizers to run until GC is run (in Jython, gc.collect() isn't
> how it is invoked though).
Yes, now that I know to try it, gc.collect() would have fixed the problem.
But I'm not sure where I would have learned to do so. The documentation
for __del__ is out of date.
The documentation lists a variety of reasons that __del__ might not get
called (it doesn't claim to be exhaustive but it does list some cases
that I consider pretty obscure). It doesn't list nested recursive functions.
One strategy is to update the __del__ and gc documentation to add this
case. Another strategy is to update the __del__ documentation to say:
"if you want this to be executed deterministically in CPython, call
gc.collect()". Or both.