[PyKDE] destructor not getting called?
Kaleb Pederson
kpederson at mail.ewu.edu
Fri Nov 8 17:33:11 GMT 2002
>On Fri, 2002-11-08 at 01:50, Kaleb Pederson wrote:
>> I'm using a global QSettings object throughout my application. For
some
>> reason, when the program closes, the destructor on my QSettings
object is >not
> getting called. As it is the destructor that actually writes
everything >to
>> disk (in order to cache the data), none of my settings are getting
saved. >Can
>> I manually call it? I'm pretty sure that this used to work on
previous
>> PyQt/Qt versions.
>
> The reason you're having problems is most likely because there is no
> such thing as a destructor in Python. I assume that you, like many
> before you, are treating the __del__() method as a destructor but the
> reality is there is no guarantee that __del__() will be called on
> program exit. The Python Language Reference recommends that you only
use
> __del__() methods to "do the absolute minimum needed to maintain
> external invariants". See
> http://www.python.org/doc/current/ref/customization.html for more
> information.
That was not one of my assumptions in this case. I'm using a module
level global that contains a reference to my wrapped QSettings class
wherein a member variable is assigned the QSettings object.
My only assumption was that once the reference count hit zero, that PyQt
would call the destructor of the C++ object to avoid any memory leaks.
I never explicitly call delete on the object; instead, I simply let it
go out of scope at application close.
Thanks for the link though. As Python has a GC, writing the __del__
call has never been a priority to me. In fact, I never considered it
the destructor of an object but merely a suggestion to the GC.
--Kaleb
More information about the PyQt
mailing list