Qml图片和内存释放

Qml images and memory releasing

我注意到分配给 Image 的内存没有释放。

在没有启动应用程序的情况下,系统具有以下内存值:423MiB / 1985MiB(通过 nvidia-smi 检查)

当我启动应用程序并单击(更改图像源)几次时,使用的内存在增加(单击一次增加 4-5MB):1950MiB / 1985MiB

将 "cache" 属性 设置为 false 没有帮助。

我找到了解决方法:更改图像可见性,但在这种情况下需要很多图像项。

是否存在使用 "source" 属性 而不是 "visible" 的解决方案?

qml 来源:

Image {
    id: trg
    anchors.fill: parent
    cache: false

    states: [
        State {
            name: "on"
            PropertyChanges {
                target: trg
                source: "qrc:/1.png"
            }
        },
        State {
            name: "off"
            PropertyChanges {
                target: trg
                source: "qrc:/2.png"
            }
        }
    ]
}

MouseArea {
    property bool isOn: false
    anchors.fill: parent

    onClicked: {
        if (isOn) {
            trg.state = "on";
        }
        else {
            trg.state = "off";
        }
        isOn = !isOn;
    }
}

不幸的是,这是一个错误(QTBUG-61754 和更多),已经在 qt 5.9.2 快照中修复(我以前使用 5.9.1 版本)。