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

QToolBar::clear() leaks memory

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • None
    • 5.12.9, 5.15.1
    • Widgets: Main Window
    • EWDK2004 and msvc2019 19.27.29111 tools, Windows 10 pro 2004 x64
    • 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. 20201023102915.png
          54 kB
          Nill Frog
        2. 20201023103006.png
          63 kB
          Nill Frog
        3. 20201023103132.png
          62 kB
          Nill Frog
        4. 20201023103307.png
          56 kB
          Nill Frog
        5. 20201023103428.png
          51 kB
          Nill Frog
        6. 20201023103907.png
          58 kB
          Nill Frog
        7. 20201023103936.png
          52 kB
          Nill Frog
        8. qtoolbar_memory_leaks.zip
          2 kB
          Nill Frog

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews