Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2098

Memory leak in Pyside signal when connected to QML slot

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.14.1
    • PySide
    • None
    • macOS, Windows
    • e0a44ab3c8 (pyside/pyside-setup/dev) e0a44ab3c8 (pyside/tqtc-pyside-setup/dev) e0a44ab3c8 (pyside/tqtc-pyside-setup/tqtc/dev)

    Description

      Precondition:

      1. Class with signal 
      incomingHubsIndices: QtCore.SignalInstance = QtCore.Signal(dict)
      
      1. The signal is connected to QML slot
      2. Sample code is attcahed
      3. The timer callback method is called from a timer with a 1s period

       
      Result:
      Memory leak(video is attached)
      Ref count after is greater than before emit
      If I try to send Qt object instead of python

      incomingHubsIndices: QtCore.SignalInstance = QtCore.Signal(QJsonValue)
      
      def timer_callback(self): 
          test_data = {n: {"TEST" : 123456789} for n in range(50000)} 
          print("before emit" + str(sys.getrefcount(test_data)))
          qt_object = QtCore.QJsonValue.fromVariant(test_data)
          self.incomingHubsIndices.emit(qt_object) 
          print("after emit" + str(sys.getrefcount(test_data)))
      

      The memory leak is absent
      This code is from my application which I can't share. That's why you can see more RAM usage than just with the sample script.
       

      Python 3.10.6
      Qt 6.4.1 (x86_64-little_endian-lp64 shared (dynamic) debug build; by GCC 11.3.0) 
      
      file:///pyside2098/main.qml:9:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
      qt.pyside.libpyside: qtMethodMetacall #6 "on_completed()"
      Worker.on_completed()
      qt.pyside.libpyside: qtMethodMetacall #7 "timeout()"
      
      #0 Worker.timeout(): before emit: 2
      qt.pyside.libpyside: qtMethodMetacall #5 "dictSignal(PyObject)"
      qml: +++++++++++++++++++++++++++: QVariant(PySide::PyObjectWrapper, 0x7f1180a67440)
                           after emit: 3
      qt.pyside.libpyside: qtMethodMetacall #7 "timeout()"
      
      #1 Worker.timeout(): before emit: 2
      qt.pyside.libpyside: qtMethodMetacall #5 "dictSignal(PyObject)"
      qml: +++++++++++++++++++++++++++: QVariant(PySide::PyObjectWrapper, 0x7f1180a67400)
                           after emit: 3
       

      Attachments

        Issue Links

          For Gerrit Dashboard: PYSIDE-2098
          # Subject Branch Project Status CR V

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              vadym_savchuk Vadym Savchuk
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes