destructors in python

Fredrik Lundh fredrik at pythonware.com
Wed Sep 15 04:26:11 EDT 1999


> I can hypothesize as to why what I expected did not occur: Is the fact
> that the __del__ of the first object comes after the next Foo is
> created a consequence of f not going out of scope between iterations
> of the for loop?

probably.

> Can I be guaranteed that the destructor of an object will be invoked
> whenever it is collected

yes.

> and collection will happen "close" to where the object goes out
> of scope?

no.

> Will python ever exit without destroying all objects it knows about
> (assuming no reference count blunders in extensions).

yes.  it makes a good attempt, but it doesn't guarantee anything.
see: http://www.python.org/doc/essays/cleanup.html

> Is the behavior of destructors a Python GC implementation detail?

yes.

> Should I worry about a new garbage collector implementation changing
> the behavior of destructor calls in future versions of Python?

only if you depend on how things work today...

</F>





More information about the Python-list mailing list