2017-08-28 76 views
3

我注意到分配給Image的內存未被釋放。Qml圖像和內存釋放

在不啓動應用程序的系統具有以下存儲器值:423MiB/1985MiB(經由NVIDIA-SMI選中)

當我啓動應用程序並點擊(改變圖像源)幾次使用存儲器正在增加(1點擊添加4-5MB):1950MiB/1985MiB

將「cache」屬性設置爲false並沒有幫助。

我找到了解決方法:更改圖像可見性,但在這種情況下需要很多圖像項目。

解決方案是否存在使用「源」屬性不「可見」?

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; 
    } 
} 
+1

是的,緩存系統/ gs在QML中很糟糕。 – folibis

回答

2

不幸的是,這是一個錯誤(QTBUG-61754和一些更多)已經被固定在QT 5.9.2快照(我用5.9.1版本)。