Unsolved QML Loader Or createComponent/createObject memory management
-
I am developing application using Qt/QML in qnx and ubuntu desktop. I have used QML Loader to load the qml file.when i load the file using loader it occupies memory but thing is when i load and unload the file in loader, every time i load file it takes few memory and memory is continuous increasing. Actually in my application around 200 qml pages need to load, each page it increases memory and when i unload the page not decreasing memory, same behaviour for createComponent/createObject also. can any one provide the solution?
-
its hard to say anything w/o qt version and code samples
-
QT 5.3.2
Following is sample code, in main qml i am loading Samplerect1.qml and Samplerect2.qml
main.qmlimport QtQuick 2.3
import QtQuick.Controls 1.2Rectangle {
id: mainAppWind
visible: true
width: 640
height: 480
// title: qsTr("Hello World")signal closedSgnl property QtObject obj1; property QtObject obj2; property var component1 property var component2 Loader{ id: loderId1
// active: true
// asynchronous: true
}Loader{ id: loderId2
// active: true
// asynchronous: true
}Rectangle{ id: mainrect1 height: 100 width: 100 anchors.centerIn: parent color: "green" MouseArea{ anchors.fill: parent onClicked: {
// loderId1.setSource("Samplerect1.qml")
component1 = Qt.createComponent("Samplerect1.qml")
obj1 = component1.createObject(mainAppWind);
}
}
}
Rectangle{
id: mainrect12
height: 100
width: 100
anchors.top: mainrect1.top
anchors.left: mainrect1.right
// anchors.leftMargin: 50
color: "yellow"
MouseArea{
anchors.fill: parent
onClicked: {
// loderId2.setSource("Samplerect2.qml")
component2 = Qt.createComponent("Samplerect2.qml")
obj2 = component2.createObject(mainAppWind);
}
}
}Text { text: qsTr("Hello World") anchors.centerIn: parent } Component.onCompleted: { } onClosedSgnl: { console.log("destroying objecta") if(obj1) { obj1.destroy() } if(obj2) { obj2.destroy() } }
}
Samplerect1:
import QtQuick 2.3
Rectangle {
id: rectIdSamp
width: 300
height: 50
objectName: "Samplerect1"
Image {
id: idImage1
width: 50
height: 50
source: "images.jpeg"
}
Image {
id: idImage2
anchors.left: idImage1.right
width: 50
height: 50
source: "index.jpeg"
}
Image {
id: idImage3
anchors.left: idImage2.right
width: 50
height: 50
source: "index2.jpeg"
}
Image {
id: idImage4
anchors.left: idImage3.right
width: 50
height: 50
source: "images1.jpeg"
}
MouseArea{
id: mAId1
anchors.fill: parent
onClicked: {
// loderId1.setSource("")
clearData()
}
}
Text {
id: text1
anchors.left: idImage4.right
text: qsTr("text1 data")
height: 20
width: 30
font.pixelSize: 12
}
Text {
id: text2
anchors.left: idImage4.right
anchors.top: text1.bottom
text: qsTr("text2 data")
height: 20
width: 30
font.pixelSize: 12
}
Text {
id: text3
anchors.left: idImage4.right
anchors.top: text2.bottom
text: qsTr("text3 data")
height: 20
width: 30
font.pixelSize: 12
}
Text {
id: text4
anchors.left: idImage4.right
anchors.top: text3.bottom
text: qsTr("text4 data")
height: 20
width: 30
font.pixelSize: 12
}
Text {
id: text5
anchors.left: idImage4.right
anchors.top: text4.bottom
text: qsTr("text5 data")
height: 20
width: 30
font.pixelSize: 12
}
Component.onDestruction: {} function clearData() { closedSgnl() }
}
Samplerect2:
import QtQuick 2.3
Item{
id: itemId
anchors.fill: parent
Rectangle {
id: rectIdSamp
width: 300
height: 50
objectName: "Samplerect1"
anchors.left: parent.left
anchors.leftMargin: 300
Image {
id: idImage1
// anchors.left: parent.right
width: 50
height: 50
source: "images11.jpeg"
}
Image {
id: idImage2
anchors.left: idImage1.right
width: 50
height: 50
source: "index22.jpeg"
}
Image {
id: idImage3
anchors.left: idImage2.right
width: 50
height: 50
source: "index21.jpeg"
}
Image {
id: idImage4
anchors.left: idImage3.right
width: 50
height: 50
source: "images12.jpeg"
}
MouseArea{
anchors.fill: parent
onClicked: {
// loderId2.setSource("")
rectIdSamp.clearData()
}
}function clearData() { closedSgnl() } }
}