Advice needed on __del__
Fredrik Lundh
fredrik at pythonware.com
Mon May 9 16:32:23 EDT 2005
"phil" wrote:
> > Python makes no guarantees whatsover about when and how to
> > run __del__, so relying on it to remove user-visible resources is a
> > rather bad idea.
> What does that mean? Is it a destructor or not?
it's a finalizer.
most Python implementations do a reasonable attempt to call finalizers
on all objects, sooner or later, but it's not guaranteed by the language
specification:
"It is not guaranteed that __del__() methods are called for
objects that still exist when the interpreter exits."
> I create thousands of instances of objects in a geometry
> instruction program and rely heavliy on __del__ to do its
> thing. For instance when I am rotating objects, I delete and
> recreate somtimes hundreds of times. Works so far.
why do you rely on __del__ to remove your objects? why not just
leave that to the garbage collector?
(__del__ disables cycle detection, so a program that uses __del__
carelessly is more likely to leak memory than a program that doesn't
use it at all).
> 2. If Python is an oop language, meaning instances of classes
> are essential, then a reliable destructor method is essential.
Python is not C++.
</F>
More information about the Python-list
mailing list