1

In my PySide app I repeatedly update a QGraphicsPixmapItem with a new pixmap that I create from a (always differently scaled) numpy array:

# Once:
from PySide import QtGui
self._image_pixmap_item = self._scene.addPixmap(QtGui.QPixmap(width, height))

# Repeated:
image = QtGui.QImage(numpy_array, width, height)
pixmap = QtGui.QPixmap.fromImage(image)
self._image_pixmap_item.setPixmap(pixmap)

This code works fine with Python 2.7 but memory usage is constantly increasing under Python 3.4. I could fix this by manually invoking the garbage collector in each loop:

import gc
gc.collect()

but performance is (of cause) quite bad. I use Python 3.4.3 with PySide 1.2.4 and numpy 1.11.2.

Is this a bug in the (relatively new) Python 3.x support of PySide or am I missing something? Also, is there a way to directly fill the the pixmap buffer without creating a new QImage every time?

Thanks Alex

UPDATE: As workaround, using qimage2ndarray (https://github.com/hmeine/qimage2ndarray) to convert the numpy array to a QImage works perfectly well.

Alex SR
  • 11
  • 3
  • 1
    Do you get a leak using the same code with PyQt4/PyQt5? – ekhumoro Dec 07 '16 at 17:47
  • I have to say I didn't try it yet, it's part of a quite complex app that doesn't run under PyQt. I will have a look if I can separate the class and test it with PyQt. – Alex SR Dec 08 '16 at 13:04

0 Answers0