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

QObject::connect memory leak

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • None
    • 5.15.3
    • Core: Object Model
    • None
    • Linux Mint 21 Cinnamon
      Cinnamon 5.4.12
      Linux kernel 5.15.0-69-generic
    • Linux/X11

    Description

      When connecting two objects inherited from QObject, deleting one of them does not break the established connection (as it should be according to the documentation when calling the QObject destructor), which leads to a memory leak. To demonstrate this defect, a primitive test project was created in which there are two classes A and B inherited from QObject. Object B sends signals, objects A process them in the slot. In this case, object B exists throughout the entire operation of the application, and objects A are dynamically created and destroyed. Older versions such as 5.11 or newer versions such as 6.0 do not cause memory leaks with this code.
      Running this application in both debug and release results in a huge memory leak that can be observed in real time in the resource manager. Valgrind memorycheck also detects the leak and points to the line with the QObject::connect method.

      class A : public QObject
      {
          Q_OBJECT
      public slots:
          void handle(){};
      };
      
      class B : public QObject
      {
          Q_OBJECT
      signals:
          void notify();
      };
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          B b;
          while (true)
          {
             A a;
             QObject::connect(&b, &B::notify, &a, &A::handle);  // <- MEMORY LEAK
          }
      
          return app.exec();
      }
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            kess A B
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes