Qt 4.7.3, Windows
Qt 4.7.2, Linux fedora
I have a problem with a program we are currently developing here. We
repeatedly create and destroy ListView's and it seems that memory is
leaking.
Our code is in C++ (with QDeclarativeComponent::create), but one of my
co-workers wrote a QML-only version that exhibits the problem in
QMLViewer. I attached the two QML files to the present message. Load the
memory_leak.qml file in QMLViewer and press Return repeatedly (or hold
it down) to create ListView's from TemplateListView.qml.
If you check the memory used by the QMLViewer process, you will see it
increase in time. You can add pictures in the model/view to make it more
obvious.
What are we doing wrong?
--
Serge
import QtQuick 1.0
Item{
id: root
function createList(){
var qtComponent = Qt.createComponent("TemplateListView.qml");
var qtObject = qtComponent.createObject(container);
if (qtObject == null){
console.log("Error in createList() : qtObject is null !");
return;
}
container.isEmpty = false;
}
width: 500
height: 600
focus: true
Keys.onReturnPressed: if (container.isEmpty) createList()
Text{
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 40
width: 500
height: 40
text: "press Return to create a listview and the listview will auto
destructs after 100 ms."
}
Item{
id: container
property bool isEmpty: true
anchors.top: parent.top
anchors.topMargin: 100
width: 500
height: 500
}
ListModel{
id: myModel
ListElement{ label: "label1" }
ListElement{ label: "label2" }
ListElement{ label: "label3" }
ListElement{ label: "label4" }
ListElement{ label: "label5" }
ListElement{ label: "label6" }
ListElement{ label: "label7" }
ListElement{ label: "label8" }
ListElement{ label: "label9" }
ListElement{ label: "label10" }
}
}
import QtQuick 1.0
ListView{
id: template
anchors.fill: parent
opacity: 1
focus: false
model: myModel
delegate: Component{
Rectangle{
width: template.width
height: 100
color: "grey"
Text{ text: label }
}
}
highlight: Rectangle { color: "black" }
Component.onCompleted: opacity = 0;
Behavior on opacity {
NumberAnimation {
duration: 100
onRunningChanged: if (!running) {template.parent.isEmpty =
true;template.destroy();}
}
}
}
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml