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

Quick dynamic loading/unloading of QML components significantly grows memory usage

    XMLWordPrintable

Details

    • Linux/X11

    Description

      During quick repeated creation and destruction of QML components, memory usage significantly grows. On my dev machine I was able to go from ~50MB to ~4.5GB with relatively simple test application.

      I've tested these dynamic components loading options:

      • Loader
      • Qt.createComponent() + createObject() + destroy()
      • QQmlComponent::create() + object->deleteLater()

      and the memory usage is growing with each of the options. I've also tested with 
      QT_QUICK_BACKEND=software environment variable set, but that made no difference.
      I've also tracked destructor calls of created objects, but all the destructors were called as they should. Also calling QQmlEngine::trimCache(), QQmlEngine::clearComponentCache(), nor calling gc() from QML didn't drop memory down.
       
      How to simulate:
      By very fast clicking on MouseArea, change source property of Loader on each click. By doing this, I could see that at first, several (~20) instances of components have been created and after that Component.onDestruction + d'tor was called for all no more needed components. And during that memory has been growing.
       
       
      Attached you can find two test applications. loader_memory_growth.zip contains the Loader version and dynamic_loading_memory_growth.zip has version when Qt.createComponent() is used.

       

      With help of heaptrack (see attached) I could see that peak contribution to memory consumption was made by these calls.

      QRecyclePoolPrivate<QQmlJavaScriptExpressionGuard, 1024>::allocate()

      QQmlBinding::newBinding(QQmlEnginePrivate*, QQmlPropertyData const*)

       

       

      UPDATE:

      When I implemented custom loader component which works the way that it first destroys the current item by calling deleteLater() and then in the slot connected to signal QObject::destroyed() of that deleted item new item with help of QQmlComponent is created, it can be see that there is only one memory growth jump after first reload of components. And then the memory is not growing. (Yeah, there is small continuous memory growth visible, like several MB after few hundred or thousand of reloads, but that is not comparable with the object of this bug.)

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            pavel_h Pavel Hromada
            Votes:
            4 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes