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. we have use qt TableView like sample source. but the memory was leaked.
QtWS25 Last Chance

we have use qt TableView like sample source. but the memory was leaked.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
tableviewmemoryleakresolutionwith
6 Posts 2 Posters 2.2k 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.
  • liuyangL Offline
    liuyangL Offline
    liuyang
    wrote on last edited by
    #1

    we have use qt TableView like sample source. but the memory was leaked.
    please support us to prevent the memory leaks.
    Entry QML:Screen.qml

    c++ sample source:
    1)display
    beginRemoveRows(QModelIndex(), 0, 0);
    for (i = - 1; i >= 0; --i)
    {
    m_inputPointList.removeAt(i);
    }
    endRemoveRows();
    beginInsertRows(QModelIndex(), 0, loopCnt-1);
    for(i = 0 ; i < loopCnt; ++i){
    ......
    m_inputPointList.append(point);
    }
    endInsertRows();
    2) data refresh
    beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
    for (i = m_inputPointList.count() - 1; i >= 0; --i)
    {

            m_inputPointList.removeAt(i);
        }
        endRemoveRows();
        beginInsertRows(QModelIndex(), 0, loopCnt-1);
        for(i = 0 ; i < loopCnt; ++i){
           ......
            m_inputPointList.append(point);
        }
        endInsertRows();
    
    1. nondisplay
      beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
      for (i = m_inputPointList.count() - 1; i >= 0; --i)
      {

           m_inputPointList.removeAt(i);
       }
       endRemoveRows();
      
    C 1 Reply Last reply
    0
    • liuyangL liuyang

      we have use qt TableView like sample source. but the memory was leaked.
      please support us to prevent the memory leaks.
      Entry QML:Screen.qml

      c++ sample source:
      1)display
      beginRemoveRows(QModelIndex(), 0, 0);
      for (i = - 1; i >= 0; --i)
      {
      m_inputPointList.removeAt(i);
      }
      endRemoveRows();
      beginInsertRows(QModelIndex(), 0, loopCnt-1);
      for(i = 0 ; i < loopCnt; ++i){
      ......
      m_inputPointList.append(point);
      }
      endInsertRows();
      2) data refresh
      beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
      for (i = m_inputPointList.count() - 1; i >= 0; --i)
      {

              m_inputPointList.removeAt(i);
          }
          endRemoveRows();
          beginInsertRows(QModelIndex(), 0, loopCnt-1);
          for(i = 0 ; i < loopCnt; ++i){
             ......
              m_inputPointList.append(point);
          }
          endInsertRows();
      
      1. nondisplay
        beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
        for (i = m_inputPointList.count() - 1; i >= 0; --i)
        {

             m_inputPointList.removeAt(i);
         }
         endRemoveRows();
        
      C Offline
      C Offline
      cheezus
      wrote on last edited by
      #2

      @liuyang Are you aware of how memory leaks are created in JavaScript? It's subtly different than in C++. Think of objects in JavaScript like shared_ptr in C++: as long as you have a reference to the object, it will not be garbage collected.

      liuyangL 2 Replies Last reply
      0
      • C cheezus

        @liuyang Are you aware of how memory leaks are created in JavaScript? It's subtly different than in C++. Think of objects in JavaScript like shared_ptr in C++: as long as you have a reference to the object, it will not be garbage collected.

        liuyangL Offline
        liuyangL Offline
        liuyang
        wrote on last edited by
        #3

        @cheezus we've confirmed that there is not memory leak on c++ side.

        can you tell me how to attach files.
        the sample source is listed folloing.
        please tell me the reason of leak.

        MyTableView.qml
        import QtQuick 2.5
        import QtQuick.Controls 1.4
        import QtQuick.Controls.Styles 1.4
        import ...

        MyItem {
        id: myTableView

        /* テーブルビュー */
        property QtObject tableViewStyle: QtObject {
            //common
            property real opacity: 1.0
            property int fontPixelSize: Style.basicFont.pixelSize
            property int leftMargin: 8
            property int rightMargin: 8
        
            //header
            property int headerBorderWidth: 0
            property int headerInsideBorderWidth: 1
            property color headerInsideBorderColor: Style.basicColorStyle.gray5
            property color headerBgColor: Style.basicColorStyle.darkblue
            property int headerRowHeight: 28
            property color headerFontColor: Style.basicColorStyle.white
        
            //body
            property color bodyBgColor: Style.basicColorStyle.white
            property color bodyBgStripeColor: Style.basicColorStyle.peerblue
            property color bodySelectedBgColor: Style.basicColorStyle.lightblue
            property int bodyRowHeight: 30
            property int bodyBorderWidth: 1
            property color bodyBorderColor: Style.basicColorStyle.gray2
            property color bodySelectedBorderColor: Style.basicColorStyle.blue
            property int bodyInsideBorderWidth: 1
            property color bodyInsideBorderColor: Style.basicColorStyle.gray3
            property color bodyFontColor: Style.basicColorStyle.black
            property color itemBgColor: "transparent"
        
            //drag
            property color dropAreaColor: Style.basicColorStyle.lightblue
            property color dropAreaBorderColor: Style.basicColorStyle.vividblue
            property int dropAreaBorderWidth: 2
        }
        
        property Component customItemDelegate: null
        
        property var displayItem: null
        property bool dragDropEnable: false
        property string dropKey: "dropKey"
        property bool resizeable: false
        property bool verticalScroll: false
        property var expansionTitle: null
        /* 一ページに表示可能の最大行数、verticalScroll=false時無視する */
        property int showRowCount: 10
        property alias currentRow: tableView.currentRow
        readonly property alias rowCount: tableView.rowCount
        property alias onfocus: tableView.focus
        
        /* 上位エレメントへ通知 */
        signal rowMoved(int from, int to);
        signal rowSelected(int rowIndex);
        
        enabled: displayItem === null ? true : displayItem.enabled
        visible: displayItem === null ? true : displayItem.visible
        
        property int resizeColIndex: 0
        
        property real resizeColBasicWidth
        
        signal resizeColumnWidth(real addWidth)
        
        onResizeColumnWidth: {
            if(resizeable === true)
            {
                if(tableView.isExistColumn(resizeColIndex) === true &&
                        tableView.getColumn(resizeColIndex).width + addWidth > myTableView.resizeColBasicWidth)
                {
                    tableView.getColumn(resizeColIndex).width += addWidth;
                }
            }
        }
        
        function addColumn(column) {
            return tableView.addColumn(column);
        }
        
        function insertColumn(index, column) {
            return tableView.insertColumn(index, column);
        }
        
        /* 指定する行をテーブルの先頭に表示する。 */
        function positionTableRowAtTop(row)
        {
            //rowは-1より大きい、かつ、TableViewの行数より小さいの場合は、
            //パラメータrowで指定したテーブル行をmyTableViewの先頭に表示する。
            if(row > -1 && row < tableView.rowCount)
            {
                tableView.positionViewAtRow(row,ListView.Beginning);
            }
        }
        
        C 1 Reply Last reply
        0
        • C cheezus

          @liuyang Are you aware of how memory leaks are created in JavaScript? It's subtly different than in C++. Think of objects in JavaScript like shared_ptr in C++: as long as you have a reference to the object, it will not be garbage collected.

          liuyangL Offline
          liuyangL Offline
          liuyang
          wrote on last edited by
          #4

          @cheezus
          QML sample source url:https://bugreports.qt.io/browse/QTBUG-53509

          1 Reply Last reply
          0
          • liuyangL liuyang

            @cheezus we've confirmed that there is not memory leak on c++ side.

            can you tell me how to attach files.
            the sample source is listed folloing.
            please tell me the reason of leak.

            MyTableView.qml
            import QtQuick 2.5
            import QtQuick.Controls 1.4
            import QtQuick.Controls.Styles 1.4
            import ...

            MyItem {
            id: myTableView

            /* テーブルビュー */
            property QtObject tableViewStyle: QtObject {
                //common
                property real opacity: 1.0
                property int fontPixelSize: Style.basicFont.pixelSize
                property int leftMargin: 8
                property int rightMargin: 8
            
                //header
                property int headerBorderWidth: 0
                property int headerInsideBorderWidth: 1
                property color headerInsideBorderColor: Style.basicColorStyle.gray5
                property color headerBgColor: Style.basicColorStyle.darkblue
                property int headerRowHeight: 28
                property color headerFontColor: Style.basicColorStyle.white
            
                //body
                property color bodyBgColor: Style.basicColorStyle.white
                property color bodyBgStripeColor: Style.basicColorStyle.peerblue
                property color bodySelectedBgColor: Style.basicColorStyle.lightblue
                property int bodyRowHeight: 30
                property int bodyBorderWidth: 1
                property color bodyBorderColor: Style.basicColorStyle.gray2
                property color bodySelectedBorderColor: Style.basicColorStyle.blue
                property int bodyInsideBorderWidth: 1
                property color bodyInsideBorderColor: Style.basicColorStyle.gray3
                property color bodyFontColor: Style.basicColorStyle.black
                property color itemBgColor: "transparent"
            
                //drag
                property color dropAreaColor: Style.basicColorStyle.lightblue
                property color dropAreaBorderColor: Style.basicColorStyle.vividblue
                property int dropAreaBorderWidth: 2
            }
            
            property Component customItemDelegate: null
            
            property var displayItem: null
            property bool dragDropEnable: false
            property string dropKey: "dropKey"
            property bool resizeable: false
            property bool verticalScroll: false
            property var expansionTitle: null
            /* 一ページに表示可能の最大行数、verticalScroll=false時無視する */
            property int showRowCount: 10
            property alias currentRow: tableView.currentRow
            readonly property alias rowCount: tableView.rowCount
            property alias onfocus: tableView.focus
            
            /* 上位エレメントへ通知 */
            signal rowMoved(int from, int to);
            signal rowSelected(int rowIndex);
            
            enabled: displayItem === null ? true : displayItem.enabled
            visible: displayItem === null ? true : displayItem.visible
            
            property int resizeColIndex: 0
            
            property real resizeColBasicWidth
            
            signal resizeColumnWidth(real addWidth)
            
            onResizeColumnWidth: {
                if(resizeable === true)
                {
                    if(tableView.isExistColumn(resizeColIndex) === true &&
                            tableView.getColumn(resizeColIndex).width + addWidth > myTableView.resizeColBasicWidth)
                    {
                        tableView.getColumn(resizeColIndex).width += addWidth;
                    }
                }
            }
            
            function addColumn(column) {
                return tableView.addColumn(column);
            }
            
            function insertColumn(index, column) {
                return tableView.insertColumn(index, column);
            }
            
            /* 指定する行をテーブルの先頭に表示する。 */
            function positionTableRowAtTop(row)
            {
                //rowは-1より大きい、かつ、TableViewの行数より小さいの場合は、
                //パラメータrowで指定したテーブル行をmyTableViewの先頭に表示する。
                if(row > -1 && row < tableView.rowCount)
                {
                    tableView.positionViewAtRow(row,ListView.Beginning);
                }
            }
            
            C Offline
            C Offline
            cheezus
            wrote on last edited by
            #5

            @liuyang I'm saying that JavaScript "leaks" ind ifferent ways than C++. If you do not know how JavaScript leaks, you should learn that first.

            liuyangL 1 Reply Last reply
            0
            • C cheezus

              @liuyang I'm saying that JavaScript "leaks" ind ifferent ways than C++. If you do not know how JavaScript leaks, you should learn that first.

              liuyangL Offline
              liuyangL Offline
              liuyang
              wrote on last edited by
              #6

              @cheezus
              JavaScipt source doesn't leak now.but QML side still leaks.please .

              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