diff options
author | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2011-08-12 13:25:27 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-12 14:02:44 +0200 |
commit | 882831e39e882ea4a7f7b3e6ea719b969951778f (patch) | |
tree | f0878413d2c7076a7ffc3b17f6cb8e83b6e0c5a9 /src/declarative/items/qsgitem.cpp | |
parent | 313ebbea192dae510db59b506e98b88734f3885b (diff) |
Fixed QSGNode leak.
QSGItem was setting its node pointer to 0 without deleting it.
Change-Id: I8b52d02069410b1dfc0057f926a52c946ef348a2
Reviewed-on: http://codereview.qt.nokia.com/2910
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/declarative/items/qsgitem.cpp')
-rw-r--r-- | src/declarative/items/qsgitem.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp index 2298be1341..c2abc46ab9 100644 --- a/src/declarative/items/qsgitem.cpp +++ b/src/declarative/items/qsgitem.cpp @@ -1718,15 +1718,34 @@ QSGItem::QSGItem(QSGItemPrivate &dd, QSGItem *parent) d->init(parent); } +#ifndef QT_NO_DEBUG +static int qt_item_count = 0; + +static void qt_print_item_count() +{ + qDebug("Number of leaked items: %i", qt_item_count); + qt_item_count = -1; +} +#endif + /*! Destroys the QSGItem. */ QSGItem::~QSGItem() { +#ifndef QT_NO_DEBUG + --qt_item_count; + if (qt_item_count < 0) + qDebug("Item destroyed after qt_print_item_count() was called."); +#endif + Q_D(QSGItem); + if (d->parentItem) + setParentItem(0); + else if (d->canvas && d->itemNodeInstance) + QSGCanvasPrivate::get(d->canvas)->cleanup(d->itemNodeInstance); // cleanup root // XXX todo - optimize - setParentItem(0); while (!d->childItems.isEmpty()) d->childItems.first()->setParentItem(0); @@ -1824,9 +1843,6 @@ void QSGItem::setParentItem(QSGItem *parentItem) QSGCanvas *parentCanvas = parentItem?QSGItemPrivate::get(parentItem)->canvas:0; if (d->canvas != parentCanvas) { - if (d->canvas && d->itemNodeInstance) - QSGCanvasPrivate::get(d->canvas)->cleanup(d->itemNodeInstance); - QSGItemPrivate::InitializationState initState; initState.clear(); d->initCanvas(&initState, parentCanvas); @@ -2021,6 +2037,8 @@ void QSGItemPrivate::initCanvas(InitializationState *state, QSGCanvas *c) c->mouseGrabberItem = 0; if ( hoverEnabled ) c->hoverItems.removeAll(q); + if (itemNodeInstance) + c->cleanup(itemNodeInstance); } canvas = c; @@ -2031,7 +2049,6 @@ void QSGItemPrivate::initCanvas(InitializationState *state, QSGCanvas *c) if (canvas && hoverEnabled && !canvas->hasMouseTracking()) canvas->setMouseTracking(true); - // XXX todo - why aren't these added to the destroy list? itemNodeInstance = 0; opacityNode = 0; clipNode = 0; @@ -2198,6 +2215,15 @@ QSGItemPrivate::QSGItemPrivate() void QSGItemPrivate::init(QSGItem *parent) { +#ifndef QT_NO_DEBUG + ++qt_item_count; + static bool atexit_registered = false; + if (!atexit_registered) { + atexit(qt_print_item_count); + atexit_registered = true; + } +#endif + Q_Q(QSGItem); baselineOffset.invalidate(); |