question on garbage collection for python
Matteo Dell'Amico
della at toglimi.linux.it
Tue Jun 1 10:33:31 EDT 2004
David Stockwell wrote:
> The questions here are:
> If in my code if I forget to close a file, when will the file be
> closed? Is it when something goes out of scope? Or will it close when
> the python session ends?
It isn't specified: it will be collected before the end of the program.
I think that CPython would do it when the refcount goes to 0, whereas in
Jython it will happen "sometimes in the future". Don't count on it, though!
> If I define a class of somesort, is there a way I can have a destructor
> method (like I would under C++ ?)
The __del__ method.
--
Ciao,
Matteo
More information about the Python-list
mailing list