Skip to content

Commit f003901

Browse files
committed
skip QImage leak workaround for PySide2 >= 5.12
the leak was addressed in PYSIDE-140
1 parent d4b9d63 commit f003901

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def paintEvent(self, event):
6161

6262
if QT_API == "PyQt6":
6363
from PyQt6 import sip
64-
ptr = sip.voidptr(buf)
64+
ptr = int(sip.voidptr(buf))
6565
else:
6666
ptr = buf
6767
qimage = QtGui.QImage(
@@ -74,7 +74,8 @@ def paintEvent(self, event):
7474
# Adjust the buf reference count to work around a memory
7575
# leak bug in QImage under PySide.
7676
if QT_API in ('PySide', 'PySide2'):
77-
ctypes.c_long.from_address(id(buf)).value = 1
77+
if QtCore.__version_info__ < (5, 12):
78+
ctypes.c_long.from_address(id(buf)).value = 1
7879

7980
self._draw_rect_callback(painter)
8081
finally:

lib/matplotlib/backends/backend_qtcairo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def paintEvent(self, event):
2929
buf = self._renderer.gc.ctx.get_target().get_data()
3030
if QT_API == "PyQt6":
3131
from PyQt6 import sip
32-
ptr = sip.voidptr(buf)
32+
ptr = int(sip.voidptr(buf))
3333
else:
3434
ptr = buf
3535
qimage = QtGui.QImage(
@@ -38,7 +38,8 @@ def paintEvent(self, event):
3838
# Adjust the buf reference count to work around a memory leak bug in
3939
# QImage under PySide.
4040
if QT_API in ('PySide', 'PySide2'):
41-
ctypes.c_long.from_address(id(buf)).value = 1
41+
if QtCore.__version_info__ < (5, 12):
42+
ctypes.c_long.from_address(id(buf)).value = 1
4243
_setDevicePixelRatio(qimage, self.device_pixel_ratio)
4344
painter = QtGui.QPainter(self)
4445
painter.eraseRect(event.rect())

0 commit comments

Comments
 (0)