Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt/QML Image memory consumption
Forum Updated to NodeBB v4.3 + New Features

Qt/QML Image memory consumption

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 2.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rogerzanoni
    wrote on last edited by
    #1

    Hi everyone, I work on an application that consists in a series of small minigames and has a QQuickView that loads a main.qml file with a Loader element. We use this Loader to swich between the minigames and they have lots of images. The problem is that the memory used to render the image elements isn't being released. I made a small sample qml aplication that keeps switching the current component in a loader to simulate our application behaviour:

    import QtQuick 2.7
    
    Item {
        id: root
    
        width: 1920
        height: 1080
    
        Component {
            id: image1Component
    
            Image {
                source: "00-piscina.png"
                anchors.fill: parent
            }
        }
    
        Component {
            id: image2Component
    
            Image {
                source: "01-canyon.png"
                anchors.fill: parent
            }
        }
    
        Loader {
            id: loader
            sourceComponent: image1Component
            anchors.fill: parent
        }
    
        Timer {
            repeat: true
            interval: 100
            running: true
            onTriggered: {
                loader.sourceComponent = loader.sourceComponent == image1Component ? image2Component : image1Component;
            }
        }
    }
    

    When I run this code, the allocated memory keeps going up until my laptop freezes. The Loader element documentation stated that "If the source or sourceComponent changes, any previously instantiated items are destroyed", so, the allocated memory for images should be released, right?

    I also ran some tests using massif to see what is allocating memory, and these are my results:

    Running using qmlscene:

    1_1503055606339_massif.out.2663.graph.png

    0_1503055606338_massif.out.2663.analysis.png

    Running using qmlscene --software (tryng to change rendering to see if results would be different):

    3_1503055606339_massif.out.3810.software.graph.png

    2_1503055606339_massif.out.3810.software.analysis.png

    Loading the same main.qml file using the following main.cpp:

    #include <QtQuick/QQuickView>
    #include <QGuiApplication>
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQuickView view;
        view.setSource(QUrl("main.qml"));
        view.show();
    
        return app.exec();
    }
    

    5_1503055606339_massif.out.5384.cpp.graph.png

    4_1503055606339_massif.out.5384.cpp.analysis.png

    I'm not sure this is s a leak, but I'll start digging bug reports, thanks in advance if someone expeperienced the same problem and know a workaround for this

    kshegunovK 1 Reply Last reply
    0
    • R rogerzanoni

      Hi everyone, I work on an application that consists in a series of small minigames and has a QQuickView that loads a main.qml file with a Loader element. We use this Loader to swich between the minigames and they have lots of images. The problem is that the memory used to render the image elements isn't being released. I made a small sample qml aplication that keeps switching the current component in a loader to simulate our application behaviour:

      import QtQuick 2.7
      
      Item {
          id: root
      
          width: 1920
          height: 1080
      
          Component {
              id: image1Component
      
              Image {
                  source: "00-piscina.png"
                  anchors.fill: parent
              }
          }
      
          Component {
              id: image2Component
      
              Image {
                  source: "01-canyon.png"
                  anchors.fill: parent
              }
          }
      
          Loader {
              id: loader
              sourceComponent: image1Component
              anchors.fill: parent
          }
      
          Timer {
              repeat: true
              interval: 100
              running: true
              onTriggered: {
                  loader.sourceComponent = loader.sourceComponent == image1Component ? image2Component : image1Component;
              }
          }
      }
      

      When I run this code, the allocated memory keeps going up until my laptop freezes. The Loader element documentation stated that "If the source or sourceComponent changes, any previously instantiated items are destroyed", so, the allocated memory for images should be released, right?

      I also ran some tests using massif to see what is allocating memory, and these are my results:

      Running using qmlscene:

      1_1503055606339_massif.out.2663.graph.png

      0_1503055606338_massif.out.2663.analysis.png

      Running using qmlscene --software (tryng to change rendering to see if results would be different):

      3_1503055606339_massif.out.3810.software.graph.png

      2_1503055606339_massif.out.3810.software.analysis.png

      Loading the same main.qml file using the following main.cpp:

      #include <QtQuick/QQuickView>
      #include <QGuiApplication>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQuickView view;
          view.setSource(QUrl("main.qml"));
          view.show();
      
          return app.exec();
      }
      

      5_1503055606339_massif.out.5384.cpp.graph.png

      4_1503055606339_massif.out.5384.cpp.analysis.png

      I'm not sure this is s a leak, but I'll start digging bug reports, thanks in advance if someone expeperienced the same problem and know a workaround for this

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      Hi,
      Sounds like a bug. This is a user forum and you'd probably have more luck asking your question in the mailing list, where you can find some of Qt's developers. So I suggest you try that if no one here has anything to add in the following few days.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • R Offline
        R Offline
        rogerzanoni
        wrote on last edited by
        #3

        Asked for help on the mailing lists and looks like it's a new issue, I created a bug report for it.

        mailing list thread: http://lists.qt-project.org/pipermail/interest/2017-August/027876.html
        bug report: https://bugreports.qt.io/browse/QTBUG-62642

        kshegunovK 1 Reply Last reply
        1
        • R rogerzanoni

          Asked for help on the mailing lists and looks like it's a new issue, I created a bug report for it.

          mailing list thread: http://lists.qt-project.org/pipermail/interest/2017-August/027876.html
          bug report: https://bugreports.qt.io/browse/QTBUG-62642

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          Thank you for posting your findings here as well!

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • R Offline
            R Offline
            rogerzanoni
            wrote on last edited by
            #5

            The bug is related to https://bugreports.qt.io/browse/QTBUG-61754 and I confirmed that this patch fixes the problem: https://codereview.qt-project.org/#/c/202781/

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved