[PyQt] pyqt circular references & garbage collection

charles chen charles.chen at temboo.com
Tue Jul 31 21:11:07 BST 2007


   Thanks Phil for your help with our memory lapse.

   We've come across another issue:  the Python garbage collector isn't sussing out circular references properly.

   A previous post by you say that this should be working:

http://www.riverbankcomputing.com/pipermail/pyqt/2007-May/016237.html

   Here's a simple demonstration:

>>> from PyQt4.QtCore import QObject
>>> class q(QObject):
...   def init(self):
...     QObject.init(self)
...   def __del__(self):
...     print 'q deleted.'
...
>>> q1 = q()
>>> q1 = None
q deleted.
>>> q2 = q()
>>> q2.circularReference = q2
>>> q2 = None
>>> q3 = q()
>>> q3.circularReference = q3
>>> q3.deleteLater()
>>> q3 = None
>>> import gc
>>> gc.collect()
0
>>> q4 = q()
>>> q4.circularReference = q4
>>> q4.circularReference = None
>>> q4 = None
q deleted.

   q2 and q3 are never gc'ed.

   We're also seeing this in production.  Are we doing something wrong?  

Charles.

see: http://www.google.com/search?source=ig&hl=en&q=pyqt+%22circular+references%22&btnG=Google+Search


Phil Thompson <phil at riverbankcomputing.co.uk> wrote: On Monday 30 July 2007 5:16 pm, charles chen wrote:
>    We're having trouble seeing the QMdiArea's subWindowActivated signal.
>
>    Is this related to the "signal/slot handling fix." from 7/16-7/20?
> http://www.riverbankcomputing.com/Downloads/Snapshots/PyQt4/ChangeLog
>
>    We're using:
> sip-snapshot-20070612.zip
> PyQt-win-commercial-4-snapshot-20070612.zip
>
> The relevant code:
>
>    self.__workspace__ = QMdiArea()
>    QObject.connect( self.__workspace__, SIGNAL('subWindowActivated (
> QMdiSubWindow * window )'), self.handleSubwindowActivated )
>
>    def handleSubwindowActivated(self, ignore=None ):
>         ...
>
> Here's a link to the Qt docs of the signal:
> http://doc.trolltech.com/4.3/qmdiarea.html#subWindowActivated

Don't pass argument names to SIGNAL().

Phil

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070731/e1ce1428/attachment.html


More information about the PyQt mailing list