Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 078ddc1

Browse files
committed
Memory leak for Cursor useblit=True on PySide/Python3
There is a memory leak in PySide under Python3. When creating QImage objects from a data buffer the reference to the buffer is not released. This leads to a memory leak when moving the cursor around the window, and eventually a crash. A workaround is to manually set the reference counter to the correct value `1` after creating the QImage object. This is a temporary local variable, and no side effects are expected.
1 parent 7c7e614 commit 078ddc1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/matplotlib/backends/backend_qt5agg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ def paintEvent(self, e):
125125
stringBuffer = reg.to_string_argb()
126126
qImage = QtGui.QImage(stringBuffer, w, h,
127127
QtGui.QImage.Format_ARGB32)
128+
# Adjust the stringBuffer reference count to work around a memory leak bug
129+
# in QImage() under PySide on Python 3.x
130+
ctypes.c_long.from_address(id(stringBuffer)).value=1
131+
128132
pixmap = QtGui.QPixmap.fromImage(qImage)
129133
p = QtGui.QPainter(self)
130134
p.drawPixmap(QtCore.QPoint(l, self.renderer.height-t), pixmap)

0 commit comments

Comments
 (0)