Qt/QML Image memory consumption



  • 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


  • Qt Champions 2016

    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.



  • 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


  • Qt Champions 2016

    Thank you for posting your findings here as well!



  • 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/


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.