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. Memory is not releasing even aftr closing the tab of QTabWidget!!??
QtWS25 Last Chance

Memory is not releasing even aftr closing the tab of QTabWidget!!??

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 6.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.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    I am using a tabwidget and adding tabs dynamically in runtime...
    Each tab contains many widgets....
    But if i close a tab, its memory is not releasing....how can i handle it?

    code in adding tab
    @
    ui->tabWidget_unfiltered->addTab(filesTable,FileName);
    @

    and for closing tab
    @
    QWidget *tab=ui->tabWidget_unfiltered->widget(index);
    ui->tabWidget_unfiltered->removeTab(index);
    delete tab;
    @

    Here each tab contains a table widget....
    And storing each those table in a hash table as
    QHash<QString,QTableWidget*> StoredTables;

    Hence when i delete that tab, i'm just removing this hash entry as..
    @
    StoredTables.remove(RmovedFilename);
    @

    but when i check in Task bar->memory(private eorking set) , the memory is not deallocating after closing the tab....
    What should i do?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      According to the "addTab":http://developer.qt.nokia.com/doc/qt-4.8/qtabwidget.html#addTab documentation I'm not sure that the parent of your page will be the tab itself, so that removing a tab will cause the memory to be freed. Who is actually the parent of your tab content?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aurora
        wrote on last edited by
        #3

        hmmm...sorry i dont know.....
        I just added tab as @ ui->tabWidget_filtered->addTab(t,filename); @

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          [quote author="aurora" date="1329208881"]but when i check in Task bar->memory(private eorking set), the memory is not deallocating after closing the tab....[/quote]

          I don't think that's a feasible way to check for memory leaks, because the system library may or may not return memory to the operating system immediately on <code>delete</code> (there are good reasons to not do so). You are better using tools dedicated to find memory leaks, like valgrind or alike.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            [quote author="aurora" date="1329221309"]hmmm...sorry i dont know.....
            I just added tab as @ ui->tabWidget_filtered->addTab(t,filename); @[/quote]

            You should know how the "t" is created and how is its parent.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aurora
              wrote on last edited by
              #6

              [quote author="fluca1978" date="1329224088"]
              You should know how the "t" is created and how is its parent.[/quote]

              Ya i know how i created....
              Its as below....
              @
              QTableWidget *t;
              t= new QTableWidget(0,TagCount,this);
              @

              and adding it to the new tab of the tab widget....
              Then

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Anticross
                wrote on last edited by
                #7

                @QHash<QString,QTableWidget*> StoredTables;@ As I see you store pointers to QTableWidget in hash, so if you make @new@ somewhere you need to @delete@ to free your memory not just remove items from your hash but also free your memory.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fluca1978
                  wrote on last edited by
                  #8

                  [quote author="aurora" date="1329366026"]
                  @
                  QTableWidget *t;
                  t= new QTableWidget(0,TagCount,this);
                  @
                  [/quote]

                  So your table is created without a parent, and unless it is reparented by a layout manager or another widget you need explicitly to destroy it.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lgeyer
                    wrote on last edited by
                    #9

                    [quote author="aurora" date="1329208881"]
                    code in adding tab
                    @
                    ui->tabWidget_unfiltered->addTab(filesTable,FileName);
                    @

                    and for closing tab
                    @
                    QWidget *tab=ui->tabWidget_unfiltered->widget(index);
                    ui->tabWidget_unfiltered->removeTab(index);
                    delete tab; // <--
                    @
                    [/quote]

                    The widget is deleted correctly.

                    Again, a non-shrinking working set does not prove a memory leak by any means. Your system library may or may not return the memory on delete, the operating system may or may not leave unused pages in the working set.

                    If you think you might have a memory leak use a dedicated tool, like valgrind, Purify or Visual Studio to detect the leak, not the Windows task manager (or any other similar tool, like top).

                    The source of your "memory leak" is the use of an improper tool to detect it.

                    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