Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86368

QQmlContext leak when connecting to and destroying dynamically created object

    XMLWordPrintable

Details

    Description

      When creating an object with Component.createObject, then connecting to a signal on it and destroying it, qml will leak QQmlContext objects over time. Here's a minimal example:

          import QtQuick 2.11
          
          Item {
              id: root
              signal outer
              Component {
                  id: comp
                  Item {
                      signal inner
                  }
              }
                Timer{
                  repeat: true
                  interval: 50
                  running: true
                  onTriggered: {
                      let obj = comp.createObject(root);
                      root.outer.connect(obj.inner)
                      //WORKAROUND
                      //root.outer.disconnect(obj.inner)
                      obj.destroy()
                      gc()
                  }
              }  
      //"Objects are not destroyed
      //the instant destroy() is called, but are cleaned up sometime between the end
      //of that script block and the next frame (unless you specified a non-zero
      //delay)."
              /*Component.onCompleted: {
                  while (true) {
                      let obj = comp.createObject(root);
                      root.outer.connect(obj.inner)
                      obj.destroy()
                      gc()
                  }
              }*/
          }
      
      

      The signal to signal connection prevents the object from cleanup. Either disconnect should happen automatically or the documentation should mention, that disconnect is needed.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              agolubev Andrei Golubev
              hhvaal Harald Hvaal
              Votes:
              1 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: