Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
None
-
6.5.2, 6.6.2
-
None
-
Windows 10 (x64), Python 3.10.12
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