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

QToolBar::clear() leaks memory

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P1: Critical
    • Resolution: Unresolved
    • Affects Version/s: 5.12.9, 5.15.1
    • Fix Version/s: None
    • Component/s: Widgets: Main Window
    • Labels:
    • Environment:
      EWDK2004 and msvc2019 19.27.29111 tools, Windows 10 pro 2004 x64
    • Platform/s:
      Windows

      Description

      In QtCreator,Just create a qmake project, simply with ui class:

      ......
      class MainWindow : public QMainWindow
      ......

       

      Add a private QToolBar member, and one slot:

      public slots:
          void refresh_toolbar();
      private: 
          QToolBar *tb;
      ......

       

      In the MainWindow's constructor, create the tb instance and call refresh_toolbar():

       

      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          tb = new QToolBar(this);
          addToolBar(tb);
      
          refresh_toolbar();
      }
      
      void MainWindow::refresh_toolbar()
      {
          static int gg = 0;
          QList<QAction*> acts = tb->actions();
      
          tb->clear(); // Here actions's memory is not released!
      
          // This should release those actions and free the memory,
          // Qt-5.9.9-mingw32 does that OK,
          // Qt-5.12.9-msvc2019 and Qt-5.15.1-msvc2019 leaks memory
          foreach (QAction* act, acts) {
              delete act;
          }
      
          for(int i = 0; i < 150; ++i)
          {
              int title = gg * 1000 + i;
              QAction *action = tb->addAction(QString::number(title));
              action->setData(i);
              action->setCheckable( true );
              action->setChecked( title % 3 );
          }
      
          if(gg < 1000)
              QTimer::singleShot(gg++ ? 10 : 5000, this, SLOT(refresh_toolbar()));
      }
      ...

      Build and run the program, it's memory usage (see at windows task manager)  is growing up......

       

      Qt-5.9.9-mingw32-gcc-9.3-i686 is build from source and not affected.

      Qt-5.12.9-msvc2019(19.27.29111)-x86_64 is build from source, Qt-5.15.1-dynamic-msvc2019-x86_64 is from https://github.com/martinrotter/qt5-minimalistic-builds/releases/tag/5.15.1 .

       

       

        Attachments

        1. qtoolbar_memory_leaks.zip
          2 kB
        2. 20201023102915.png
          20201023102915.png
          54 kB
        3. 20201023103006.png
          20201023103006.png
          63 kB
        4. 20201023103132.png
          20201023103132.png
          62 kB
        5. 20201023103307.png
          20201023103307.png
          56 kB
        6. 20201023103428.png
          20201023103428.png
          51 kB
        7. 20201023103907.png
          20201023103907.png
          58 kB
        8. 20201023103936.png
          20201023103936.png
          52 kB

          Issue Links

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

            Activity

              People

              Assignee:
              qt.team.quick.subscriptions Qt Quick and Widgets Team
              Reporter:
              nillfrog Nill Frog
              Votes:
              3 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews