summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorGareth Stockwell <ext-gareth.stockwell@nokia.com>2010-10-19 15:46:18 (GMT)
committerGareth Stockwell <ext-gareth.stockwell@nokia.com>2010-10-26 13:22:59 (GMT)
commitf417a6e7729a506e5a59e7fd38e03166515198b1 (patch)
tree090d140dde5a47d0e11428c809b496ca48dc767a /src/gui
parent586fc2a9ead06a8478bdc380b775f18000741745 (diff)
downloadQt-f417a6e7729a506e5a59e7fd38e03166515198b1.zip
Qt-f417a6e7729a506e5a59e7fd38e03166515198b1.tar.gz
Qt-f417a6e7729a506e5a59e7fd38e03166515198b1.tar.bz2
Remove widget subtree from backing store tracker when reparented
When a native widget is reparented such that the value of maybeBackingStore() changes, it and all of its native descendents must be removed from the old QWidgetBackingStoreTracker. If this is not done, the backing store may not be deleted when the top-level widget is hidden, thereby consuming memory unnecessarily. Task-number: MOBILITY-1315 Reviewed-by: Jason Barron Reviewed-by: bnilsen
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qwidget.cpp20
-rw-r--r--src/gui/kernel/qwidget_p.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index 9b44f15..6c64ffc 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -236,6 +236,17 @@ void QWidgetBackingStoreTracker::unregisterWidget(QWidget *w)
}
}
+/*!
+ \internal
+ Recursively remove widget and all of its descendents.
+ */
+void QWidgetBackingStoreTracker::unregisterWidgetSubtree(QWidget *widget)
+{
+ unregisterWidget(widget);
+ foreach (QObject *child, widget->children())
+ if (QWidget *childWidget = qobject_cast<QWidget *>(child))
+ unregisterWidgetSubtree(childWidget);
+}
QWidgetPrivate::QWidgetPrivate(int version)
: QObjectPrivate(version)
@@ -10031,7 +10042,16 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
if (newParent && isAncestorOf(focusWidget()))
focusWidget()->clearFocus();
+ QTLWExtra *oldTopExtra = window()->d_func()->maybeTopData();
+ QWidgetBackingStoreTracker *oldBsTracker = oldTopExtra ? &oldTopExtra->backingStore : 0;
+
d->setParent_sys(parent, f);
+
+ QTLWExtra *topExtra = window()->d_func()->maybeTopData();
+ QWidgetBackingStoreTracker *bsTracker = topExtra ? &topExtra->backingStore : 0;
+ if (oldBsTracker && oldBsTracker != bsTracker)
+ oldBsTracker->unregisterWidgetSubtree(this);
+
if (desktopWidget)
parent = 0;
diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h
index 6c89659..ca1e3fc 100644
--- a/src/gui/kernel/qwidget_p.h
+++ b/src/gui/kernel/qwidget_p.h
@@ -122,6 +122,7 @@ public:
void registerWidget(QWidget *w);
void unregisterWidget(QWidget *w);
+ void unregisterWidgetSubtree(QWidget *w);
inline QWidgetBackingStore* data()
{