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.