[PyKDE] Bad Memory Leak

Andre Reitz reitz at inworks.de
Wed Dec 6 15:04:24 GMT 2006


Thank you for your quick answer...

Sounds great,
but memory usage increases continuously.
Do you have an idea why?
Is there a bug on C++/SIP side?

Greetings, Andre'

Here agaign the test code:

Please watch Memory usage in Windows Task-Manager
while holding down the ESCAPE-Key, so you will
see the mem-usage of the process grows.
If you remove the QObject.connect(...) line...
it will *not* grow.

My Problem is that we are developing a large long running
application in PyQt and we would have plenty of these leaks.

--------------------------------------------------
from qt import *
app=QApplication([])
def c():
     print "cc"

sss=SIGNAL("clicked()")
while 1:
     d=QDialog()
     b=QPushButton("x",d)
     QObject.connect(b,sss,c) #<-------XXX
     d.exec_loop()
     del b
     del d

--------------------------------------------------


Giovanni Bajo wrote:
> Andreas Pakulat wrote:
> 
>> Note this is python, not C++, del foobar doesn't immediately free the
>> memory associated.
> 
> That's incorrect. "del foobar" removes a reference; if it's the last
> reference and there are no loops, the memory is immediately collected. Now,
> there are no reference loops at the Python level, so the memory *is*
> collected when the "del" statement is executed.
> 
> Specifically, the first "del b" collected the Python-side instance of the
> push button (the C++-side of the pushbutton is owned by the dialog as it's a
> chiled). The second "del d" collects the Python-side instance of the dialog,
> which in turns causes a deletion of the C++-side of the dialog (since it has
> no parent, so it's fully owned by Python); the C++ destructor also destroys
> the C++-side of the pushbutton. So, after the second "del", all the memory
> is reclaimed, with no need for the Python cyclic GC to kick in.




More information about the PyQt mailing list