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

QMenu memory leak on clear()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P4: Low P4: Low
    • None
    • 5.15.2
    • None
    • Windows

      When clearing a QMenu, actions are only removed, not deleted. Minimal example:

      QMenu m_pMenuOwner = new QMenu("Menu owner");
      QMenu m_pMenuOther = new QMenu("Menu other");
      while (true) {
        for (quint64 j = 0; j < 10000; ++j) {
          auto* pAction = new QAction("Action", m_pMenuOwner);
          m_pMenuOwner->addAction(pAction);
          m_pMenuOther->addAction(pAction);
        }
        // without this line the actions get deallocated, with it they don't
       
      m_pMenuOwner->clear(); //
        m_pMenuOther->clear();
        m_pMenuOwner->clear();
      }

      I've attached the Qt Creator project and a gif with the memory consumption.

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            cezar_petriuc Cezar Petriuc
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes