Hi,
I was investigating a PyQt garbage collection
bug :
http://www.riverbankcomputing.com/pipermail/pyqt/2011-August/030376.html
I the attached test case, I get a
segmentation fault in PyQt when the garbage
collector kicks in.
When using PySide, it appears the garbage collection
has no effect, so there seems to be a memory
leak.
Notice that fixing this memory leak is probably non
trivial, see PyQt bug report.
Best regards,
Erik
"""Test the behaviour of the qt bindings in various circumstances.
"""
import unittest
from PySide import QtGui, QtCore
class GarbageCollectionCase( unittest.TestCase ):
def setUp(self):
self.application = QtGui.QApplication.instance()
if not self.application:
import sys
self.application = QtGui.QApplication(sys.argv)
def test_cyclic_dependency( self ):
"""Create 2 widgets with a cyclic dependency, so that they can
only be removed by the garbage collector, and then invoke the
garbage collector in a different thread.
"""
import gc
class CyclicChildWidget(QtGui.QWidget):
def __init__( self, parent ):
super( CyclicChildWidget, self ).__init__( parent )
self._parent = parent
class CyclicWidget(QtGui.QWidget):
def __init__( self ):
super( CyclicWidget, self ).__init__()
CyclicChildWidget( self )
# turn off automatic garbage collection, to be able to trigger it
# at the 'right' time
gc.disable()
alive = lambda :sum( isinstance(o,CyclicWidget) for o in gc.get_objects() )
#
# first proof that the wizard is only destructed by the garbage
# collector
#
cycle = CyclicWidget()
self.assertTrue( alive() )
del cycle
self.assertTrue( alive() )
gc.collect()
self.assertFalse( alive() )
#
# now run the garbage collector in a different thread
#
cycle = CyclicWidget()
del cycle
self.assertTrue( alive() )
class GarbageCollectingThread(QtCore.QThread):
def run(thread):
self.assertTrue( alive() )
# assertian failure with PyQt here, and core dump
gc.collect()
self.assertFalse( alive() )
thread = GarbageCollectingThread()
thread.start()
thread.wait()
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside