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