[PyKDE] Memory leak: Cycles with QObject's doesn't get collected

Phil Thompson phil at riverbankcomputing.co.uk
Sun Jun 19 15:32:54 BST 2005


On Friday 17 June 2005 5:36 pm, Giovanni Bajo wrote:
> Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> >> I think I have found another memory leak. When you create cycles with
> >> QObjects they aren't collected. This doesn't happen with pure python
> >> objects (as expected), but in that case I have found an strange
> >> behaviour when you set the gc.DEBUG_SAVEALL flag (that isn't PyQT
> >> related, but take that in account if you add gc debug flags). See the
> >> attached script and their logs.
> >
> > That's because SIP has never supported the cyclic garbage collector. That
>
> is
>
> > now fixed and your test script shows no leak.
>
> I just verified that the same script *does* cause a memory leak if you use
> QWidget instead of QObject as test class:
>
> Is GC enabled?: 1
> Has TestClass a __del__ method? (if True, it will be marked as
> unreachable): False
> PY Version:   2.3.4 (#1, Feb  2 2005, 12:11:53)
> [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)]
> QT Version:   3.3.4
> PYQT Version: snapshot-20050417
> SIP Version:  4.2.1 (snapshot-20050430-314)
>
> VmSize: 25320 Kb VmRss: 8732 Kb
> VmSize: 25320 Kb VmRss: 8736 Kb
> VmSize: 25320 Kb VmRss: 8744 Kb
> VmSize: 25320 Kb VmRss: 8748 Kb
> VmSize: 25320 Kb VmRss: 8756 Kb
> VmSize: 25320 Kb VmRss: 8764 Kb
> VmSize: 25320 Kb VmRss: 8768 Kb
> VmSize: 25320 Kb VmRss: 8776 Kb
> VmSize: 25320 Kb VmRss: 8784 Kb
> VmSize: 25320 Kb VmRss: 8788 Kb
> VmSize: 25320 Kb VmRss: 8796 Kb
> VmSize: 25320 Kb VmRss: 8804 Kb
> VmSize: 25320 Kb VmRss: 8808 Kb
> VmSize: 25320 Kb VmRss: 8816 Kb
> [...]
>
> I have attached the updated script.

I see the leak but it only appears with QWidget and it's sub-classes. It 
doesn't appear with QObject and it's sub-classes. As far as SIP and PyQt are 
concerned there is no implementation difference between the two.

Using sip.settracemask() on the C++ ctors and dtors shows that the dtors match 
the ctors.

I can only conclude that the leak is within Qt or X.

Phil




More information about the PyQt mailing list