QML Memory Usage
Solved
QML and Qt Quick
-
Hi everyone :)
I'm calling a QML function repeatedly from C++. During the first few calls everything is fine and pretty fast, but after some time, everything is getting super slow. The QML Profiler tells me, that allocated memory is not cleared, but I don't really understand why. Here is the Profiler output:
This is the QML file including the javascript function that gets called:
import QtQuick 2.5 import QtQuick.Controls 2.1 import QtLocation 5.5 import QtPositioning 5.3 import com.connection 1.0 Map { anchors.fill: parent property variant points: ({}) property var component Plugin { id: googlemaps name: "googlemaps" PluginParameter { name: "googlemaps"; value: "http://maps.googleapis.com/maps/api/js?sensor=false" } } Component.onCompleted: { component = Qt.createComponent("mapcircle.qml"); points = new Array(); for( var i_type in supportedMapTypes ) { print (supportedMapTypes[i_type].name) if( supportedMapTypes[i_type].name.localeCompare( "Hybrid" ) === 0 ) { activeMapType = supportedMapTypes[i_type] } } } id: map plugin: googlemaps // Javascript function // Remove old points from map and add new ones function add_points(array_lat, array_lon) { var loop_size; if (map.points.length > array_lat.length) loop_size = map.points.length else loop_size = array_lat.length var newPoints = [array_lat.length] var object for (var i=0; i < loop_size; i++) { if (i < map.points.length) { map.removeMapItem(map.points[i]) } if (i < array_lat.length) { object = component.createObject(map, { "center": QtPositioning.coordinate(array_lat[i], array_lon[i])}) map.addMapItem(object) newPoints.push(object) } } map.points = newPoints } }
For me it seems to be this line: (I reduced the code for testing purposes a bit and even without plotting the data onto the map the execution is getting very slow)
object = component.createObject(map, { "center": QtPositioning.coordinate(array_lat[i], array_lon[i])})
-
It doesn't seem like
Map::removeMapItem()
destroys the item but just removes it from the map, so you might want to try callingdestroy()
on the items that are removed from the map:map.removeMapItem(map.points[i]) map.points[i].destroy()