Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-88248

QObject orphaned connections soft-leak

    XMLWordPrintable

    Details

    • Platform/s:
      All

      Description

      Since 5.14 'receiver' QObjects will, on destruction, move its connection in the 'sender' object to an orphaned list, due for cleanup later.

      The orphan list is cleaned up on the sender's next signal emission, or on its destruction.

      In certain circumstances the sender object rarely or never emits signals, and is long-lived. This leads to a long-lived soft leak every time a connection is made to it.

      Can be seen with this example, which is a reduced example of what happens in QNetworkAccessManager:

      int main(int argc, char* argv[])
      {
          QCoreApplication qapp(argc, argv);
          QThread th;
          th.start();
          for (int i = 0; i < 1'000'000; ++i) {
              QObject *o = new QObject;
              QObject::connect(&th, &QThread::finished, o, &QObject::deleteLater);
              o->moveToThread(&th);
              QMetaObject::invokeMethod(o, &QObject::deleteLater);
              QThread::msleep(10);
          }
          return 0;
      }
      

        Attachments

        1. patch1.png
          patch1.png
          190 kB
        2. patch2.png
          patch2.png
          769 kB

          Issue Links

          For Gerrit Dashboard: QTBUG-88248
          # Subject Branch Project Status CR V

            Activity

              People

              Assignee:
              fabiankosmale Fabian Kosmale
              Reporter:
              manordheim MÃ¥rten Nordheim
              PM Owner:
              Vladimir Minenko Vladimir Minenko
              RnD Owner:
              Alex Blasche Alex Blasche
              Votes:
              4 Vote for this issue
              Watchers:
              23 Start watching this issue

                Dates

                Created:
                Updated: