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. How to delete the instance (or release the memory) created by Repeater
Qt 6.11 is out! See what's new in the release blog

How to delete the instance (or release the memory) created by Repeater

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 1.2k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    obt-young
    wrote on last edited by
    #1

    I haven't found a way to release the memory alloced by the Repeater.
    Anyone could tell me how to delete the instance (or release the memory) created by Repeater.
    Thanks in advance.

    J.HilkJ 1 Reply Last reply
    0
    • O obt-young

      I haven't found a way to release the memory alloced by the Repeater.
      Anyone could tell me how to delete the instance (or release the memory) created by Repeater.
      Thanks in advance.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @obt-young

      just a guess, as you don't show any code

      function clearRepeater(){
           myRepeater.model = undefined
           gc()
      }
      
      Column {
          Repeater {
             id:myRepeater
              model: ["apples", "oranges", "pears"]
              Text { text: "Data: " + modelData }
          }
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        obt-young
        wrote on last edited by
        #3

        Thanks for you reply.
        I try your method in a example code as follows:

        import QtQuick 2.5
        import QtQuick.Window 2.2
        import QtQuick.Controls 1.4
        
        
        Window {
            visible: true
            width: 300
            height: 300
            title: qsTr("Hello World")
        
            Grid{
                anchors.fill: parent
                spacing: 10
        
                Repeater{
                    id:rp
                    model:3
                    delegate: Component{
                        Rectangle{
                            id:rc
                            color:"red"
                            width: 20
                            height: 20
                        }
                    }
                }
            }
        
            Button{
                id:rebtn
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                width: 20
                height: 20
                text:"-"
                onClicked: {
                    rp.model = undefined
                    gc()
                }
            }
        
            Button{
                anchors.bottom: parent.bottom
                anchors.right:rebtn.left
                width: 20
                height: 20
                text:"+"
                onClicked: {
                    rp.model=3
                }
            }
        }
        
        

        It seems doesn't work , the memory increased every time i click the "+" button , but does not decrease when i click the "-" button

        J.HilkJ raven-worxR 2 Replies Last reply
        0
        • O obt-young

          Thanks for you reply.
          I try your method in a example code as follows:

          import QtQuick 2.5
          import QtQuick.Window 2.2
          import QtQuick.Controls 1.4
          
          
          Window {
              visible: true
              width: 300
              height: 300
              title: qsTr("Hello World")
          
              Grid{
                  anchors.fill: parent
                  spacing: 10
          
                  Repeater{
                      id:rp
                      model:3
                      delegate: Component{
                          Rectangle{
                              id:rc
                              color:"red"
                              width: 20
                              height: 20
                          }
                      }
                  }
              }
          
              Button{
                  id:rebtn
                  anchors.bottom: parent.bottom
                  anchors.right: parent.right
                  width: 20
                  height: 20
                  text:"-"
                  onClicked: {
                      rp.model = undefined
                      gc()
                  }
              }
          
              Button{
                  anchors.bottom: parent.bottom
                  anchors.right:rebtn.left
                  width: 20
                  height: 20
                  text:"+"
                  onClicked: {
                      rp.model=3
                  }
              }
          }
          
          

          It seems doesn't work , the memory increased every time i click the "+" button , but does not decrease when i click the "-" button

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @obt-young
          2 points.

          • How to you monitor the memory increase ?
          • The GC is unreliable, even when manually called. The nature of JS...

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          2
          • O obt-young

            Thanks for you reply.
            I try your method in a example code as follows:

            import QtQuick 2.5
            import QtQuick.Window 2.2
            import QtQuick.Controls 1.4
            
            
            Window {
                visible: true
                width: 300
                height: 300
                title: qsTr("Hello World")
            
                Grid{
                    anchors.fill: parent
                    spacing: 10
            
                    Repeater{
                        id:rp
                        model:3
                        delegate: Component{
                            Rectangle{
                                id:rc
                                color:"red"
                                width: 20
                                height: 20
                            }
                        }
                    }
                }
            
                Button{
                    id:rebtn
                    anchors.bottom: parent.bottom
                    anchors.right: parent.right
                    width: 20
                    height: 20
                    text:"-"
                    onClicked: {
                        rp.model = undefined
                        gc()
                    }
                }
            
                Button{
                    anchors.bottom: parent.bottom
                    anchors.right:rebtn.left
                    width: 20
                    height: 20
                    text:"+"
                    onClicked: {
                        rp.model=3
                    }
                }
            }
            
            

            It seems doesn't work , the memory increased every time i click the "+" button , but does not decrease when i click the "-" button

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @obt-young said in How to delete the instance (or release the memory) created by Repeater:

            delegate: Component{
            Rectangle{
            id:rc
            color:"red"
            width: 20
            height: 20
            }
            }

            i don't know if thats the cause of the behavior you are seeing, but normally you do not need to wrap your delegate item in a Component.
            Also you can try to log the delegate's destruction to make sure if it actually gets deleted or not.

            delegate: Rectangle{
                    id:rc
                    color:"red"
                    width: 20
                    height: 20
            
                    Component.onDestruction: console.log("Repeater delegate destruction")
                }
            

            If you can see this message your delegate items are destroyed and your memory increase comes from somewhere else in your code.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            5

            • Login

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