2010/10/20 Thomas Sturm <[email protected]>:
> 2. On deleting that instance its reference self.main disappears, and it 
> cannot play a role for what happens subsequently.
It doesn't, references do not magically disappear.  On the contrary,
the key point of references is, that the object referred to remains
alive as long as the reference is valid.

It may happen, that Qt deletes the underlying C++ object, but Python
doesn't know this, and still keeps the wrapper object alive, because
there are still valid references to it.  As long as there is any
reference, this object is still alive, and its __del__ method will
consequently not be invoked.

Pythons memory management should be considered non-deterministic, just
like with other managed platforms.  __del__ is therefore not the
Python equivalent to a C++ destructor, and it should not be used this
way.  I do know your indent in using __del__ in this specific
situation, but avoid it, if at all possible.  Move cleanup work to
other methods (e.g. a event callback or a slot connected to the
"deleted" signal), which are guaranteed to be invoked in a certain
situation.

If you can't, then at least use a weak reference to refer to objects,
whose lifetime should not be controlled by Python.

> 3. Since the instance of MyWorker lives outside the Qt widget hierarchy, I 
> would expect its destructor to be called by Python on termination of the 
> program.
As stated in the documentation [1], the Python interpreter does not
guarantee invocation of "__del__()" for any object still alive at
interpreter termination.

Sebastian Wiesner

[1] http://docs.python.org/reference/datamodel.html#object.__del__
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to