QMainWindow: don't grow memory when modifying tabbed docks while hidden

QMainWindow tries to avoid memory allocations by caching tab bars that
are no longer used. That cache is populated when the layout is
activated.

The layout might never be activated when the main window is never shown,
in which case adding and removing dock widgets at runtime will
continuously allocate more memory for tab bars that are created.

A workaround is to call QMainWindow::layout()->activate() explicitly in
application code, once all dock widgets have been removed. This change
avoids that applications have to do that.

Change-Id: I70eb585d2120f0b7b73f59c3ee65d7242c12ec59
Fixes: QTBUG-83135
Pick-to: 5.15
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
bb10
Volker Hilsheimer 2020-04-21 17:24:03 +02:00
parent ed86a4f253
commit 70ad404203
1 changed files with 9 additions and 0 deletions

View File

@ -1779,6 +1779,15 @@ bool QMainWindowTabBar::event(QEvent *e)
QTabBar *QMainWindowLayout::getTabBar()
{
if (!usedTabBars.isEmpty()) {
/*
If dock widgets have been removed and added while the main window was
hidden, then the layout hasn't been activated yet, and tab bars from empty
docking areas haven't been put in the cache yet.
*/
activate();
}
QTabBar *result = nullptr;
if (!unusedTabBars.isEmpty()) {
result = unusedTabBars.takeLast();