Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. RadioButton is leaking when loaded and unloaded

RadioButton is leaking when loaded and unloaded

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 235 Views
  • 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.
  • O Offline
    O Offline
    Odder
    wrote on last edited by Odder
    #1

    Hi,
    I have encountered a problem with the QML Loader element and the QML RadioButton element. When I load and unload a QML Component that contains a RadioButton element I observe memory leaks.

    I have made a small example:

    main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    
        return app.exec();
    }
    

    main.qml:

    import QtQuick 2.1
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Loader memory leak test")
    
        Loader {
            id: loader
            anchors {
                horizontalCenter: parent.horizontalCenter
                verticalCenter: parent.verticalCenter
            }
        }
    
        Row {
            anchors {
                bottom: parent.bottom
                horizontalCenter: parent.horizontalCenter
                margins: 10
            }
            spacing: 10
    
            Button {
                text: "Component 1"
    
                onClicked: {
                    loader.source = "Page1.qml"
                    gc()
                }
            }
    
            Button {
                text: "Component 2"
    
                onClicked: {
                    loader.source = "Page2.qml"
                    gc()
                }
            }
        }
    }
    
    

    Page1.qml:

    import QtQuick 2.1
    import QtQuick.Controls 1.2
    
    Item {
    
        Repeater {
            model: 1000
            anchors.fill: parent
    
            RadioButton {
                text: "Component 1"
            }
        }
    }
    

    Page2.qml:

    import QtQuick 2.1
    import QtQuick.Controls 1.2
    
    Item {
    
        Repeater {
            model: 1000
            anchors.fill: parent
    
            RadioButton {
                text: "Component 2"
            }
        }
    }
    

    Has anyone else experienced this issue? If that is the case, how did you solve it?

    1 Reply Last reply
    0

    • Login

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