of destructors, open files and garbage collection

massimo s. devicerandom at gmail.com
Thu May 24 12:49:46 EDT 2007


> It will delete the *name* `item`.  It does nothing to the object that was
> bound to that name.  If the name was the only reference to that object, it
> may be garbage collected sooner or later.  Read the documentation for the
> `__del__()` method for more details and why implementing such a method
> increases the chance that the object *won't* be garbage collected!
>
> Relying on the `__del__()` method isn't a good idea because there are no
> really hard guaranties by the language if and when it will be called.

Ok, I gave a look at the docs and, in fact, relying on __del__ doesn't
look like a good idea.

Changing the code as to add an explicit method that closes dangling
filehandles is easy. It would be somehow nice because -since that
method would be added to a plugin API- it *forces* people writing
plugins to ensure a way to close their dangling files, and this may be
useful for a lot of future purposes. However I'd also like to track
references to my objects -this would help debugging a lot. How can I
do that?




More information about the Python-list mailing list