PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 763 - memory leak in QPixmap.fromImage
: memory leak in QPixmap.fromImage
Status: CLOSED ALREADYFIXED
Product: PySide
Classification: Unclassified
Component: QtGui
: HEAD
: All All
: P2 major
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-03-20 13:31 EET by Matti Airas
Modified: 2011-04-01 23:16 EEST (History)
9 users (show)

See Also:


Attachments
Test case from pastebin (807 bytes, text/x-python)
2011-03-21 18:51 EET, Hugo Parente Lima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matti Airas 2011-03-20 13:31:38 EET
ranen.ghosh@gmail.com reported on the mailing list:

Hi, I am noticing a memory leak with PySide's QPixmap.fromImage static method.
Here is a small example program to demonstrate it: http://pastebin.com/VmKncUFY

For the first 30 seconds or so, everything seems fine.  At that point, my Xorg
process's memory usage starts to shoot up at about 20M per second.

The following info may be helpful:

If I use the QPixmap's constructor with the filename as an argument, rather
than using the static QPixmap.fromImage method, I don't observe the memory
issue.

If I don't call self.lbl.setPixmap(pxmp) , I don't observe the memory issue.

If I double the timer delay, it takes roughly twice as long for the memory
spike to happen.

If I replace PySide with PyQt4 in the import statements, I do not observe this
memory issue.

--and--

In fact, I suspect that there is always a memory leak when calling QPixmap's
constructor, but that in some cases it is not noticed because some form of
optimization is preventing QPixmap construction when it is superfluous.

Note that the following code in the timer callback causes a memory blow-up, but
simply switching the pxmp assignment statements, and leaving everything else
as-is, results in no memory blow-up.

        img = QtGui.QImage('tiger.png')
        fd, pathname = tempfile.mkstemp('.bmp')
        os.close(fd)
        img.save(pathname, "BMP")
        pxmp = QtGui.QPixmap(pathname)
#        pxmp = QtGui.QPixmap('tiger.png')
        os.remove(pathname)
        self.lbl.setPixmap(pxmp)
Comment 1 Hugo Parente Lima 2011-03-21 18:51:41 EET
Created attachment 285 [details]
Test case from pastebin
Comment 2 Hugo Parente Lima 2011-03-24 23:18:18 EET
Could you run the test case under valgrind and attach the output in this
report?

I ran the test under valgrind and it said nothing useful, about QImage just a
message not related to PySide itself:

==7328==  Address 0x5f11020 is 6,080 bytes inside a block of size 8,192 free'd  
==7328==    at 0x4C2457C: free (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)                            
==7328==    by 0xB4E65BB: ??? (in /usr/lib/libpng14.so.14.5.0)                  
==7328==    by 0xB4E6929: png_destroy_read_struct (in
/usr/lib/libpng14.so.14.5.0)                                                    
==7328==    by 0xAAEBCCE: ??? (in /usr/lib/libQtGui.so.4.7.2)                   
==7328==    by 0xAABB86A: QImageReader::read(QImage*) (in
/usr/lib/libQtGui.so.4.7.2)                                                     
==7328==    by 0xAABBDEB: QImageReader::read() (in /usr/lib/libQtGui.so.4.7.2)  
==7328==    by 0xAAB146D: QImage::load(QString const&, char const*) (in
/usr/lib/libQtGui.so.4.7.2)                                                     
==7328==    by 0xAAB1604: QImage::QImage(QString const&, char const*) (in
/usr/lib/libQtGui.so.4.7.2)                                                     
==7328==    by 0x9D4951C: QImageWrapper::QImageWrapper(QString const&, char
const*) (qimage_wrapper.cpp:65)                                                 
==7328==    by 0x9D4A4C6: Sbk_QImage_Init (qimage_wrapper.cpp:304)              
==7328==    by 0x4EC6D07: type_call (in /usr/lib/libpython2.7.so.1.0)           
==7328==    by 0x4E72B52: PyObject_Call (in /usr/lib/libpython2.7.so.1.0)       

I also had ran the example for minutes without any change on process memory
(/proc/xxx/status).

Did you tested it with latest version from git?
Comment 3 Hugo Parente Lima 2011-03-25 20:56:09 EET
ping
Comment 4 ranen.ghosh@gmail.com 2011-03-28 19:52:57 EEST
Hi, I originally reported this bug to the pyside mailing list.  I was using the
latest packages for Ubuntu 10.10 as of that date (March 18).  I tested this
again with the latest version of pyside and friends from git, and there was no
memory blowup.

I then uninstalled pyside and installed the latest packages again with apt, and
the memory leak was back.  So this has apparently been fixed between the date
of the latest Ubuntu 10.10 packages and now.

Thank you.
Comment 5 Hugo Parente Lima 2011-03-28 21:01:48 EEST
Ok, thanks for the feedback!
Comment 6 Hugo Parente Lima 2011-04-01 23:16:10 EEST
Closing bug after release of PySide 1.0.1.