[PySide] QTimer reference leaks in pyside vs pyqt

Josh Pieper jjp at pobox.com
Sat Jun 14 03:41:29 CEST 2014


Philip Starkey wrote:
> 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?
> 
> 
> 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.


Thanks for giving it a try.  I ended up working around the problem by
using a signal connected to a slot with a QueuedConnection, which
didn't seem to leak anything.  I'll try to update to 1.2.2 at some
point here and will report back if anything has changed.

Regards,
Josh





More information about the PySide mailing list