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

Bug in ListView causes memory leak and app to hang indefinitely

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 6.5.3, 6.8.0
    • None
    • macOS

    Description

      While developing a chat app, I got into a bug that cause a constant memory leak while the app hangs indefinitely. To easily reproduce the bug, just run the following code and try to scroll upward, the app will hang/crash/try to allocate infinite amount of RAM. At least on my machine (Macbook Air M1 running macOS 15.0.1).

      pragma ComponentBehavior: Bound
      import QtQuick
      import QtQuick.Controls
      
      ApplicationWindow {
          id: appWindow
          width: 400
          height: 400
          visible: true    
          ListModel {
              id: testModel        
              Component.onCompleted: {
                  for (let i = 0; i < 20; i++) {
                      testModel.append({});
                  }
              }
          }    
           ListView {
              id: listView
              width: parent.width
              anchors.top: parent.top
              anchors.bottom: testButton.top
              model: testModel        
              delegate: Rectangle {
                  width: listView.width
                  height: 50
                  color: index % 2 ? "red" : "green"            
                  required property int index            
                  Component.onCompleted: {
                      listView.positionViewAtEnd();
                  }
              }        
              ScrollBar.vertical: ScrollBar {}
          }    
          Button {
              id: testButton
              anchors.bottom: parent.bottom
              anchors.horizontalCenter: parent.horizontalCenter
              text: "Click me"
              onClicked: {
                  testModel.append({});
              }
          }
      }
      

       

       

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            rubymamis Ruby Mamistvalove
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes