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

QObject orphaned connections soft-leak

    XMLWordPrintable

Details

    • All
    • c2839843f23fb5c289175cb9577981d48dd273fc

    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

          Activity

            People

              fabiankosmale Fabian Kosmale
              manordheim MÃ¥rten Nordheim
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              4 Vote for this issue
              Watchers:
              29 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: