[PyKDE] ANN: SIP v4.2rc2 Released

Phil Thompson phil at riverbankcomputing.co.uk
Fri Feb 18 23:51:46 GMT 2005


On Thursday 17 February 2005 9:56 pm, Nahuel Greco wrote:
> On Thu, 17 Feb 2005 17:03:16 -0000 (GMT)
>
> "Phil Thompson" <phil at riverbankcomputing.co.uk> wrote:
> > Gentoo (x86 and amd64). I didn't run the C++ test - I was refering to the
> > original Python test that Torsten sent me.
>
> Ok, I was confused because I tought that you were having different results
> with the C++ test, so I thinked that maybe the problem was in Qt 3.3.3 and
> in 3.3.4 it was fixed.
>
> I talked with the qt-bugs folks, they said (about the C++ test):
>
>  "Yes. The problem is that Xlib allocates memory when you call certain
>   functions (which is what the QWidget constructor ends up doing) and
>   these memory blocks are not freed before other X functions are called.
>   So if you insert a call to QApplication::processEvents() in your loop
>   then you will no longer see increased memory usage. You can check this
>   yourself by using valgrind and forcing the application to quit after
>   the loop is done (i.e. by calling abort(3)) and run valgrind with the
>   "--leak-check=yes" argument. You will then see that most, if not all,
>   of the memory used at that point is allocated by Xlib. If you call
>   QApplication::processEvents() then Xlib will have freed the memory
>   before the application terminates. Do note that this is only a problem
>   while your loop is spinning, the memory is actually freed when the loop
>   returns even though top or vmsize might tell you otherwise."
>
> So I inserted a processEvents() in the middle of the C++ loop, and now it
> seems ok. But then I tried doing the same with my Python test, inserting
> that processEvents() call, but that didn't fix it.
>
> Now I have the equivalent program done in C++ and PyQT, and the C++ one
> don't leak but the PyQT one keeps leaking. I'm attaching the new version
> of both and their output.
>
> What I don't understand is why you aren't seeing the same behaviour, I
> tried with Qt 3.3.3 / 3.3.4, with the sip/pyqt version packaged for Debian
> and with the latest sip/pyqt snapshot. So maybe the problem is in another
> library, I don't know, maybe I must install your Gentoo version and then
> copy one by one the pyqt required libraries to the Debian machine, to see
> where the correct behaviour shows. Do you have any idea of how I can
> continue the investigation?
>
> Note, the C++ program now have a weird behaviour,when you close the window,
> the process didn't finish and the memory usage begins to increase. I
> don't think that this is related to the problem.

Note that the comments below follow the consumption of a very nice Penfolds 
Thomas Hyland Cab Sav 2001...

I see the memory leak in the test_py_leak.py, but it's what I would expect 
given what the script does. Because QDialog has a parent, ownership (ie. 
responsibility for destroying the QDialog) is transfered to the parent. The 
statement...

    f = None

...has no effect at all on the memory usage. The memory would only be 
recovered when the QMainWindow instance was garbage collected.

The comments in the script state that there was no difference if the QDialog 
had no parent - I did not see that behaviour. If I changed the script...

    f = QDialog()

...it executed in constant space - no memory leak.

Phil




More information about the PyQt mailing list