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

Fix memory leaks in Shiboken

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P2: Important
    • Some future version
    • 5.15.2
    • Shiboken
    • None
    • python 3.9.5
      archlinux

    • Linux/X11
    • f34dcb84a (dev), 47d4d01ac (6.7)

    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

        Issue Links

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

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              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