Memory Management in Qml



  • Hello.
    I developed a program by Qt and Qml!
    My application has several window that works with stackview.
    every time clicked on button, stackview push new window and if clicked on back, pop window!

    in this case I confront memory leak...
    MainWindow memory is 23.7 MB
    page1: 32MB
    page3: 33.7

    agian back to main window
    MainWindow : 28MB
    page1: 33.8MB
    Page2: 33.8MB

    agian back to main window
    Page4:39.2MB
    MainWindow: 39.2MB

    each window that opens, the memory increases!
    How can solved this?

    My stackview Code :

    toolBar: BorderImage {
        border.bottom: 8
        source: "qrc:/Icons/toolbar.png"
        width: parent.width
        height: 70
        Rectangle {
            id: backButton
            width: opacity ? 60 : 0
            anchors.left: parent.left
            anchors.leftMargin: 20
            opacity: stackView.depth > 1 ? 1 : 0
            anchors.verticalCenter: parent.verticalCenter
            antialiasing: true
            height: 60
            radius: 4
            color: backmouse.pressed ? "#222" : "transparent"
            Behavior on opacity { NumberAnimation{} }
            Image {
                anchors.verticalCenter: parent.verticalCenter
                source: "qrc:/Icons/navigation_previous_item.png"
                Text {
                    font.pixelSize: 42
                    Behavior on x { NumberAnimation{ easing.type: Easing.OutCubic} }
                    x: backButton.x + backButton.width + 20
                    anchors.verticalCenter: parent.verticalCenter
                    text: "back"
                    color: "white"
                    font.family: webFont.name
                }
            }
            MouseArea {
                id: backmouse
                anchors.fill: parent
                anchors.margins: -10
                onClicked:
                {
                    stackView.pop()
                    gc()
                }
    
            }
        }
        Text {
            font.pixelSize: 42
            Behavior on x { NumberAnimation{ easing.type: Easing.OutCubic} }
            anchors.verticalCenter: parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
            color: "white"
            text: "Irsa Soft"
            font.family: webFont.name
    
        }
    }
    StackView {
            id: stackView
            anchors.fill: parent
            // Implements back key navigation
            focus: true
            Keys.onReleased: if (event.key === Qt.Key_Back && stackView.depth > 1) {
                                 stackView.pop();
                                 destroyed()
                                 gc()
                                 event.accepted = true;
                             }
    
            initialItem: Item {
    
                width: parent.width
                height: parent.height
                MainMenu {
                    anchors.fill: parent
                    onClicked : stackView.push({item:url,destroyOnPop:true})
                    onChangeToshowTraffic : stackView.push({item:url,destroyOnPop: true})
                    onChangeToSaveEnter: stackView.push({item:url,destroyOnPop: true})
                    onChangeTomission: stackView.push({item:url,destroyOnPop: true})
                }
            }
    
        }

Log in to reply
 

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