[PyKDE] Re: Memory leak & segfault with deleteLater

Giovanni Bajo rasky at develer.com
Wed Jun 29 15:46:30 BST 2005


Phil Thompson <phil at riverbankcomputing.co.uk> wrote:

> I think one way around the problem is to avoid the extra reference to the
> Python object and move the data that it contains into a separate data
> structure. In other words, weaken the link between the Python world and
> the C++ world. My concern would then be stopping the new data structure
> leaking - I need to think about it a bit more.

While I am not able to help you with this design issue, I think I have found
also a GC-counterpart of this bug:

-----------------------------------------
#!/usr/bin/env python
from qt import *

class Foo:
    pass

app = QApplication([])
w1 = QWidget(None)
w2 = QWidget(w1)
w2.xxxx = w1
w2.deleteLater()

f1 = Foo()
f2 = Foo()
f1.w = w1
f2.w = w2
f1.f = f2
f2.f = f1

del w1
del w2
del f1
del f2

app.processEvents()

import gc
gc.collect()

-----------------------------------------
Instead of a segfault, this crashes with an assertion failure in Python
itself (assuming you have assertion enabled): Modules/gcmodule.c:231: failed
assertion `gc->gc.gc_refs != 0'

This is biting me very hard now that you fixed the other GC problem, since
more things are being collected and thus this bug is exposed in many places.
-- 
Giovanni Bajo




More information about the PyQt mailing list