[PyKDE] ref leak in QWidget.reparent
Phil Thompson
phil at river-bank.demon.co.uk
Sat Nov 17 11:52:43 GMT 2001
Brent Burley wrote:
>
> Here's an example:
>
> from qt import *
>
> class MyVBox(QVBox):
> def __del__(self):
> print 'del VBox'
>
> import sys
> app = QApplication(sys.argv)
> top = QWidget()
> top2 = QWidget()
> vb = MyVBox(top)
> vb.reparent(top2, 0, QPoint());
>
> MyVBox doesn't get destroyed. If you comment out the reparent call, the
> leak goes away. Also, if you initially create the vbox with no parent,
> the leak also goes away.
>
> I think this may be related to (or at the heart of) the QScrollView leak
> I reported earlier. QScrollview calls reparent internally in addChild
> to reparent the child to its viewport. This causes the child to be
> leaked unless the child initially has no parent.
When ownership is transferred to C++ the reference count of the Python
object is increased (this is fairly new behaviour - v2.5 I think). This
is why you don't see the MyVBox object being deleted (because the
corresponding C++ QVBox is never deleted). When the C++ QVBox is
deleted, the Python object reference count will be decremented.
I've fixed QWidget.reparent() so that it does the ownership transfer
properly if the QWidget has now acquired or lost a parent.
I've also fixed a bug in ownership transfer in the cases where ownership
was already where it should be (the reference counts were screwed).
How much of a difference these make to what you are seeing/expecting
remains to be seen...
Phil
More information about the PyQt
mailing list