Memory leak when modifying a model of a MapItemView
Unsolved
QML and Qt Quick
-
When modifying the model of a MapItemView, memory usage increases indefinitely but when the model is replaced completely it works fine.
I've also tried with a custom
QAbstractListModel
where the data is changed when an external signal is triggered. the data is replaced andbeginResetModel()
andendResetModel()
are called accordingly. But the leak is still happening.A minimal example to see the effect. Change the 1 in the trigger callback to see the difference.
import QtQuick import QtLocation import QtPositioning Window { id: window width: 640 height: 480 visible: true property list<var> myModel: [] Timer { interval: 1 running: true repeat: true onTriggered: { // 1: leak happens, 0: no leak if (1) { myModel = [] for (var i = 0; i < 10; i++) { let longitude = Math.random() * 360 - 180 let latitude = Math.random() * 180 - 90 myModel[i] = QtPositioning.coordinate(latitude, longitude) } } else { let newModel = [] for (var j = 0; j < 10; j++) { let longitude = Math.random() * 360 - 180 let latitude = Math.random() * 180 - 90 newModel[i] = QtPositioning.coordinate(latitude, longitude) } myModel = newModel } } } Map { anchors.fill: parent plugin: Plugin { name: "osm" } MapItemView { model: myModel delegate: MapQuickItem { visible: true coordinate: modelData } } } }
OS: Ubuntu 20.04.6 LTS x86_64
Kernel: 5.15.0-107-generic