Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.0
-
None
-
5b39b316e (dev), 58ec2ac3d (6.5), f26d22209 (dev), 683c8ed5d (6.5), cc2054bc1 (6.5.1), e31b4220f (tqtc/6.5.1), b81f2c3f9 (dev), e2a3d76b9 (6.5), 0bf8ce702 (dev), f21ed0581 (6.5), 80da3a11d (6.5.1), 9a7dfdd57 (tqtc/6.5.1), f0109334c (dev), 7222d8a04 (6.5)
Description
Hello Qt for Python team,
PyQtGraph maintainer here, we have an issue with extra reference counts (and by extension a memory leak) to signal/slot mechanisms where a signal is connected to a lambda function that references self.
Here is a non-pyqtgraph version to replicate the issue, the psutil library is needed to track memory usage:
from PySide6 import QtCore, QtWidgets import psutil class Leaker: def __init__(self): parent = None parent = QtWidgets.QWidget() # this line seemingly makes PySide < 6.5.0 not leak wgt= QtWidgets.QSpinBox(parent) wgt.valueChanged.connect(self.mkChangeCallback(wgt)) def mkChangeCallback(self, w): return lambda *args: self.widgetChanged(w, *args) def widgetChanged(self, w, *args): pass app = QtWidgets.QApplication([]) timer = QtCore.QTimer() proc = psutil.Process() rss0 = proc.memory_info().rss cnt = 0 def timer_cb(): global cnt rss = proc.memory_info().rss print(f'{cnt}: {(rss - rss0)/1048576:.1f} MB') Leaker() cnt += 1 if cnt > 500: timer.stop() app.exit() timer.timeout.connect(timer_cb) timer.start(0) app.exec() if hasattr(app, 'exec') else app.exec_()
I'm going to mark as affecting 6.5.0 but I'm fairly certain we've seen this issue in much older versions of pyside
Here is the issue in our bug-tracker: https://github.com/pyqtgraph/pyqtgraph/issues/2672
Attachments
Issue Links
- relates to
-
PYSIDE-2646 [REG: 6.2->6.5] Connections to lambda or nested function prevent destruction of objects they refer to
- Closed
-
PYSIDE-2371 REG->6.5: Memory leak connecting signal to local function
- Closed
- resulted from
-
PYSIDE-2141 Crash when connecting/disconnecting inherited slot
- Closed
- resulted in
-
PYSIDE-2346 Connecting signal to inner function reuses first instance of inner function
- Closed
For Gerrit Dashboard: PYSIDE-2299 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
476972,11 | Fix leak connecting signals to anonymous functions | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
477326,2 | Fix leak connecting signals to anonymous functions | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
477638,3 | Fix anonymous slot memory leak test | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
477811,2 | Fix anonymous slot memory leak test | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
479751,6 | Leak fix: special consideration for functools.partial | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
479816,3 | Leak fix: special consideration for functools.partial | 6.5.1 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
479842,2 | Leak fix: special consideration for functools.partial | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
479872,2 | Leak fix: special consideration for functools.partial | tqtc/6.5.1 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
481498,2 | Revert anonymous slot memory leak fix | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
481535,2 | Revert anonymous slot memory leak fix | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
481577,3 | Revert anonymous slot memory leak fix | 6.5.1 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
481684,2 | Revert anonymous slot memory leak fix | tqtc/6.5.1 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
487671,5 | PySide6/SignalManager: Fix memory leaks connecting free methods/lambdas | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
487672,2 | PySide6: Add debug operators for DynamicSlotDataV2/GlobalReceiverV2 | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
488119,2 | PySide6: Add debug operators for DynamicSlotDataV2/GlobalReceiverV2 | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
488261,2 | PySide6/SignalManager: Fix memory leaks connecting free methods/lambdas | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
488591,3 | Update changes-6.5.2 | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
488675,2 | Update changes-6.5.2 | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |