[PySide] QTimer reference leaks in pyside vs pyqt

Philip Starkey philip.starkey at monash.edu
Fri Jun 13 07:44:22 CEST 2014


Josh Pieper <jjp <at> pobox.com> writes:

> 
> Hello, I have an application that wants to repeatedly schedule
> callbacks into the QT event loop.  With pyside, memory usage grows
> over time, as python doesn't appear to be able to free things up.
> objgraph shows a growing number of QTimer objects not being collected.
> With pyqt, this is not a problem, and neither is it with a C++
> transliteration.
> 
> I'm using pyside 1.2.1 on ubuntu 14.04.  My demonstration application
> is below. 
>
> Am I doing something wrong?
> 
> Regards,
> Josh
> 
> ----
> 
> import sys
> 
> import PySide.QtCore as QtCore
> 
> def test():
>     QtCore.QTimer.singleShot(0, test)
> 
> def main():
>     app = QtCore.QCoreApplication(sys.argv)
>     test()
>     app.exec_()
> 
> if __name__ == '__main__':
>     main()
> 


I just tested your example on Windows 8.0, Python 32-bit with PySide 1.2.2 
and see no memory leak. Might be worth updating to 1.2.2 just in case, 
otherwise it looks to be a platform specific issue.

I don't believe you are doing anything wrong though. The QTimer should post 
an event to the Qt Event loop, and the Python function should then end and 
be garbage collected (along with everything in it that Python owns). The QT 
Event loop will then run the test function again. The singleShot() method of 
QTimer doesn't return a reference to the QTimer created anyway, so Python 
shouldn't really be holding onto any QTimer references I would have thought.

Cheers,






More information about the PySide mailing list