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

QRunnable with setAutoDelete(False) leads to memory leak in PySide6

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 6.5.2, 6.6.2
    • PySide
    • None
    • Windows 10 (x64), Python 3.10.12
    • Windows

    Description

      When QRunnable object is created with setAutoDelete(False), then it is not deleted by garbage collector (when there are no more references to it) and leads to memory leak (but according to the Qt doc, when setAutoDelete is False, ownership remains with the application programmer and the QRunnable object have to be deleted by garbage collector.

      In the attached script to reproduce the problem: we have a Task class, inherited from QRunnable to run it's code in a separate thread. When task.setAutoDelete(True) (which is the default value), then everything works well: task is deleted after run() is finished. But we need to keep the task in memory some time to display it's status: so we need to keep a reference to it. So we set task.setAutoDelete(False): then QThreadPool will not delete it. And we expect, that task will be deleted (by garbage collector), when all our references to it are gone. But the task is not deleted even when gc.collect() is called, and even when program is closed.

      P.S. In PyQt 6.6.1 it works as expected.

      See this my question for the full story: https://stackoverflow.com/questions/78076185/qrunnable-with-setautodeletefalse-leads-to-memory-leak-in-pyside6

      Attachments

        1. pyside2621_pyqt.py
          2 kB
        2. pyside2621.py
          2 kB
        3. qrunnable_bug_report.py
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            ivankosik Ivan Kosik
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes