[PyKDE] Memory leak & segfault with deleteLater

Giovanni Bajo rasky at develer.com
Mon Jun 20 16:15:56 BST 2005


Hello,

two problems, which are very similar (and maybe related). The first is a
segmentation fault:

>>> from qt import *
>>> app = QApplication([])
>>> w1 = QWidget(None)
>>> w2 = QWidget(w1)
>>> w2.xxxx = w1
>>> w2.deleteLater()
>>> del w1
>>> del w2
>>> app.processEvents()
Segmentation fault

The thing I don't understand is why it does not crash if you don't add a
reference to w1 from inside w2.

The second problem is a memory leak:

>>> from qt import *
>>> app = QApplication([])
>>> import gc, weakref
>>> class Data:
...     pass
...
>>> d = Data()
>>> wd = weakref.ref(d)
>>> w1 = QWidget(None)
>>> w2 = QWidget(w1)
>>> w2.xxxxxx = w1
>>> w1.xxxxxx = d
>>> del d
>>> del w1
>>> del w2
>>> gc.collect()
0
>>> app.processEvents()
>>> gc.collect()
0
>>> print wd
<weakref at 00813690; to 'instance' at 00812FD0>

"d" should be collected as w1 and w2 are destroyed.
-- 
Giovanni Bajo




More information about the PyQt mailing list