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

QQuickWidget object stay in QML Engine cache after deletion

    XMLWordPrintable

Details

    • Windows

    Description

      We have an QQuickWidget class, which its object sometimes could be created and deleted dynamically pretty frequently - Menus and popups for example.

      Its source is set to a qml file at construction.

       

      class MyWidget: public QQuickWidget {
        MyWidget::MyWidget(QQmlEngine* engine) : QQuickWidget(engine, nullptr)
        { 
          setSource(QUrl("qrc:/qml/components/myMenu.qml")); 
          ...... 
        }
        ......
      }

       
      We noticed that the memory usage has slightly increasing trend overtime by repeatedly create MyWidget,

      After checking, this memory issue is from setSource - Looks like after an object is deleted, it's not cleared from QML engine and still stay in some caches?

      Reproduce ;

      1. Start any memory tool (in-code memory usage record like psutil, or external analysis valgrind, heob)
      2. Construct any QQuickWidget with setSource call
      3. Delete the object after 3~5 seconds (the time doesn't really matter)
      4. Repeat step 2 and 3 in a loop for a significant amount of time, like ~5 hours.

      Expected :

      • Memory consumption not increasing, stay at a flat level.

      Actual:

      • Memory consumption has minor increasing trend
      • From heap analysis, that increasing is due to allocation by setSource call.

      Note:

      • After some workaround by simply avoid repeatedly creating/deleting QQuickWidget , memory consumption no longer increase.

      Attachments

        1. leaks_v0.xml
          3.90 MB
        2. leaks.html
          3.86 MB
        3. QT.png
          QT.png
          82 kB
        4. quickwidgets_min.zip
          47 kB

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              erdingercat Yu-Ting Huang
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: