Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Memory leak when modifying a model of a MapItemView
QtWS25 Last Chance

Memory leak when modifying a model of a MapItemView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtpoqmlmapitemviewmemory leak
2 Posts 2 Posters 270 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    somso2e
    wrote on last edited by
    #1

    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 and beginResetModel() and endResetModel() 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

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yapcumt
      wrote on last edited by
      #2

      I have encountered a similar problem, which has not been resolved. However, your example does not illustrate this issue.I test the example ,when myModel = newModel,print myModel.length =0

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved