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

Fix memory leaks in Shiboken

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: Shiboken
    • Labels:
      None
    • Environment:

      python 3.9.5
      archlinux

    • Platform/s:
      Linux/X11

      Description

      the following code exhibits quite some memory leaks already, and using more of PySide only makes it worse:

      #include <Python.h>
      
      #include <QCoreApplication>
      #include <QDebug>
      
      using namespace std;
      
      void test()
      {
          qWarning() << "init";
          Py_Initialize();
      
          {
              auto mainModule = PyImport_ImportModule("__main__");
              auto globalDict = PyModule_GetDict(mainModule);
      
              auto compiled = Py_CompileString("from PySide2 import QtCore\n", "test.py", Py_file_input);
              qWarning() << compiled;
      
              auto ret = PyEval_EvalCode(compiled, globalDict, globalDict);
              qWarning() << ret;
      
              Py_XDECREF(ret);
              Py_XDECREF(compiled);
              Py_XDECREF(mainModule);
          }
      
          Py_Finalize();
          qWarning() << "deinit";
      }
      
      int main(int argc, char** argv)
      {
          QCoreApplication app(argc, argv);
          test();
          return 0;
      }
      

      Compile it with LSAN or use memcheck and set `PYTHONMALLOC=malloc` and you'll see a huge list of leaks. I'll attach the log file as it's far too large to paste it here directly.

      My expectation would be that a call to Py_Finalize would also unload all shiboken state.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            crmaurei Cristian Maureira-Fredes
            Reporter:
            milianw Milian Wolff
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes