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. QML Memory Usage
QtWS25 Last Chance

QML Memory Usage

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.9k 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.
  • D Offline
    D Offline
    danielusa
    wrote on last edited by danielusa
    #1

    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:qmlprofiler

    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])})
    
    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by jpnurmi
      #2

      It doesn't seem like Map::removeMapItem() destroys the item but just removes it from the map, so you might want to try calling destroy() on the items that are removed from the map:

      map.removeMapItem(map.points[i])
      map.points[i].destroy()
      
      D 1 Reply Last reply
      3
      • jpnurmiJ jpnurmi

        It doesn't seem like Map::removeMapItem() destroys the item but just removes it from the map, so you might want to try calling destroy() on the items that are removed from the map:

        map.removeMapItem(map.points[i])
        map.points[i].destroy()
        
        D Offline
        D Offline
        danielusa
        wrote on last edited by
        #3

        @jpnurmi That helped, thank you :) I had to force it to delete the objects with setting a time

         *.destroy(wait_ms_to_destroy)
        

        but no there are no issues left :)

        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