[PyQt] QImage memory leak in 4.10.1
Luke Campagnola
lcampagn at email.unc.edu
Thu May 23 21:21:26 BST 2013
Howdy,
I am using PyQt 4.10.1 (Py2.7-qt4.8.4-x32) on windows XP. It appears that
on this system, QImage(sip.voidptr, int, int, format) increases the
reference count to the image data object, but does not decrease the
refcount after the QImage is collected. Here's an example session, where I
am generating a QImage from a numpy array:
>>> from PyQt4 import QtGui
>>> import ctypes, weakref, sys
>>> import numpy as np
>>> data = np.zeros((100,100,4), dtype=np.ubyte)
>>> addr = ctypes.c_char.from_buffer(data,0)
>>> sys.getrefcount(addr)
2
>>> img = QtGui.QImage(addr, 100, 100, QtGui.QImage.Format_ARGB32)
>>> sys.getrefcount(addr) # QImage added 1 to reference count
3
>>> import weakref
>>> ref = weakref.ref(img)
>>> del img
>>> ref
<weakref at 0161F090; dead> # QImage was collected
>>> sys.getrefcount(addr) # but refcount is still 3
3
Can anyone recommend a good way to convert from ndarray to QImage
(preferrably without incurring any memory copy) ?
Thanks,
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130523/bcbdd21a/attachment.html>
More information about the PyQt
mailing list