Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget items Memory Leak Problem!
QtWS25 Last Chance

QTableWidget items Memory Leak Problem!

Scheduled Pinned Locked Moved Solved General and Desktop
qtablewidgetqabstractitemderowreleasememory
10 Posts 4 Posters 1.7k 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on last edited by Proton Phoenix
    #1

    Hi~
    I have QTableWidget and i am adding items through QTableWidgetItem ...
    it has 10 column some hidden ..
    everytime i add new row it increase the ram usage by 700kb to 2 megabytes ... so i think it's normal ~~
    after almost 40 rows it became 130 megabytes of usage from (90 megabytes of normal usage of the software)
    but when i need to reset QTablewidget and delete all the rows ~~
    i used for that :

    ui->tableWidget->setRowCount(0);
    

    but it stays 130 megabyte of ram usages ... it releases nothing ~~
    if i add new rows ... it use more than 130 megabytes .. even closing the widget release only the widget and and the ram usage still higher!!!
    i tried for loop with removeRow(i);
    but the same problem !!!!
    is there any solution??

    1 Reply Last reply
    0
    • jsulmJ jsulm

      @Proton-Phoenix said in QTableWidget items Memory Leak Problem!:

      Task Manager

      This is not a good tool to look for memory leaks. On Linux one would use Valgrind for example. Not sure what you can use on Windows. Maybe Visual Studio provides tools for that?

      P Offline
      P Offline
      Proton Phoenix
      wrote on last edited by Proton Phoenix
      #9

      @jsulm said in QTableWidget items Memory Leak Problem!:

      @Proton-Phoenix said in QTableWidget items Memory Leak Problem!:

      Task Manager

      This is not a good tool to look for memory leaks. On Linux one would use Valgrind for example. Not sure what you can use on Windows. Maybe Visual Studio provides tools for that?

      i found the memory leak bro
      it was this

      QSoundEffect effect;
          effect.setSource(QUrl::fromLocalFile("D:/**/**/**/**/barcode.wav"));
      
      
          effect.setLoopCount(1);
          effect.setVolume(0.40f);
          effect.play();
          qDebug()<<effect.status();
          // this the memory leak
          QEventLoop loop;
              loop.exec();
          qDebug()<<effect.Error;
      
      i used this to make a validation sound of adding values through barcode
      

      it was keep using the ram more and more not QTableWidget at all
      Thank you guys Really thank you

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi
        Did you try calling clear() on the QTableWidget ?
        https://doc.qt.io/qt-5/qtablewidget.html#clear

        Are you just adding text to the items ? as
        130 mb for 40 rows x 10 cols seems a bit much for text.

        P 1 Reply Last reply
        0
        • mrjjM mrjj

          Hi
          Did you try calling clear() on the QTableWidget ?
          https://doc.qt.io/qt-5/qtablewidget.html#clear

          Are you just adding text to the items ? as
          130 mb for 40 rows x 10 cols seems a bit much for text.

          P Offline
          P Offline
          Proton Phoenix
          wrote on last edited by Proton Phoenix
          #3

          @mrjj said in QTableWidget items Memory Leak Problem!:

          Hi
          Did you try calling clear() on the QTableWidget ?
          https://doc.qt.io/qt-5/qtablewidget.html#clear

          Are you just adding text to the items ? as
          130 mb for 40 rows x 10 cols seems a bit much for text.

          Yes The same problem with ui->tableWidget->clear();

          about the usage ..
          the software uses 90 megabyte before using the tableWidget
          and it reach 130 megabytes almost at 76 rows .. i tried it now ~~

          mrjjM 1 Reply Last reply
          0
          • P Proton Phoenix

            @mrjj said in QTableWidget items Memory Leak Problem!:

            Hi
            Did you try calling clear() on the QTableWidget ?
            https://doc.qt.io/qt-5/qtablewidget.html#clear

            Are you just adding text to the items ? as
            130 mb for 40 rows x 10 cols seems a bit much for text.

            Yes The same problem with ui->tableWidget->clear();

            about the usage ..
            the software uses 90 megabyte before using the tableWidget
            and it reach 130 megabytes almost at 76 rows .. i tried it now ~~

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Proton-Phoenix
            Hi
            Well clear() should delete all items.

            Please be aware that some Os will free the mem for use for the app but it will not
            show in Task Manager before the app is stopped.

            What platform/device are you testing on ?

            P 1 Reply Last reply
            1
            • mrjjM mrjj

              @Proton-Phoenix
              Hi
              Well clear() should delete all items.

              Please be aware that some Os will free the mem for use for the app but it will not
              show in Task Manager before the app is stopped.

              What platform/device are you testing on ?

              P Offline
              P Offline
              Proton Phoenix
              wrote on last edited by Proton Phoenix
              #5

              @mrjj said in QTableWidget items Memory Leak Problem!:

              @Proton-Phoenix
              Hi
              Well clear() should delete all items.

              Please be aware that some Os will free the mem for use for the app but it will not
              show in Task Manager before the app is stopped.

              What platform/device are you testing on ?

              all The items got deleted by clear();
              but that not releasing any mem!
              the same as setRowCount(0);
              i am using Pc With windows 10
              and Task Manager !

              jsulmJ 1 Reply Last reply
              0
              • P Proton Phoenix

                @mrjj said in QTableWidget items Memory Leak Problem!:

                @Proton-Phoenix
                Hi
                Well clear() should delete all items.

                Please be aware that some Os will free the mem for use for the app but it will not
                show in Task Manager before the app is stopped.

                What platform/device are you testing on ?

                all The items got deleted by clear();
                but that not releasing any mem!
                the same as setRowCount(0);
                i am using Pc With windows 10
                and Task Manager !

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Proton-Phoenix said in QTableWidget items Memory Leak Problem!:

                Task Manager

                This is not a good tool to look for memory leaks. On Linux one would use Valgrind for example. Not sure what you can use on Windows. Maybe Visual Studio provides tools for that?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                P 2 Replies Last reply
                2
                • jsulmJ jsulm

                  @Proton-Phoenix said in QTableWidget items Memory Leak Problem!:

                  Task Manager

                  This is not a good tool to look for memory leaks. On Linux one would use Valgrind for example. Not sure what you can use on Windows. Maybe Visual Studio provides tools for that?

                  P Offline
                  P Offline
                  Proton Phoenix
                  wrote on last edited by Proton Phoenix
                  #7

                  i am not expert at visual studio but i will try to find similar to valgrind ...
                  does using any other free process monitor ?? show me the real stats??
                  or it's the same as task manager !

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Proton Phoenix
                    wrote on last edited by
                    #8

                    Any way Thank you so much for helping me i will keep trying until i find this mem leaks

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Proton-Phoenix said in QTableWidget items Memory Leak Problem!:

                      Task Manager

                      This is not a good tool to look for memory leaks. On Linux one would use Valgrind for example. Not sure what you can use on Windows. Maybe Visual Studio provides tools for that?

                      P Offline
                      P Offline
                      Proton Phoenix
                      wrote on last edited by Proton Phoenix
                      #9

                      @jsulm said in QTableWidget items Memory Leak Problem!:

                      @Proton-Phoenix said in QTableWidget items Memory Leak Problem!:

                      Task Manager

                      This is not a good tool to look for memory leaks. On Linux one would use Valgrind for example. Not sure what you can use on Windows. Maybe Visual Studio provides tools for that?

                      i found the memory leak bro
                      it was this

                      QSoundEffect effect;
                          effect.setSource(QUrl::fromLocalFile("D:/**/**/**/**/barcode.wav"));
                      
                      
                          effect.setLoopCount(1);
                          effect.setVolume(0.40f);
                          effect.play();
                          qDebug()<<effect.status();
                          // this the memory leak
                          QEventLoop loop;
                              loop.exec();
                          qDebug()<<effect.Error;
                      
                      i used this to make a validation sound of adding values through barcode
                      

                      it was keep using the ram more and more not QTableWidget at all
                      Thank you guys Really thank you

                      1 Reply Last reply
                      2
                      • KH-219DesignK Offline
                        KH-219DesignK Offline
                        KH-219Design
                        wrote on last edited by
                        #10

                        Just a note about a non-Valgrind, windows-specific leak-checking method:

                        https://docs.microsoft.com/en-us/visualstudio/debugger/finding-memory-leaks-using-the-crt-library?view=vs-2019

                        It has been a while since I have done any extensive work on a Microsoft platform, but in my recollection crtdbg.h can do many helpful diagnostic things, although it is sometimes tricky to get all the debug build settings configured in the way that will trigger the features you seek.

                        www.219design.com
                        Software | Electrical | Mechanical | Product Design

                        1 Reply Last reply
                        3

                        • Login

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