From: Andrew den Exter Date: Fri, 29 Jun 2012 01:49:33 +0000 (+1000) Subject: Fix memory leak when cancelling incubation of view items. X-Git-Tag: upstream/5.2.1~1544 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a27feb5a95aa0756bbc37de32434111752f44e4e;p=platform%2Fupstream%2Fqtdeclarative.git Fix memory leak when cancelling incubation of view items. Don't cancel incubation of referenced object, but if incubation is cancelled remove the scriptRef held by the incubator so the data object can be released, not just when incubation has inititialized but not finalized an object. Change-Id: If2d6a4c4409dbd771d7131782023aa5e2d08eeed Reviewed-by: Martin Jones --- diff --git a/src/quick/items/qquickvisualdatamodel.cpp b/src/quick/items/qquickvisualdatamodel.cpp index 6f5934e..ddd8e16 100644 --- a/src/quick/items/qquickvisualdatamodel.cpp +++ b/src/quick/items/qquickvisualdatamodel.cpp @@ -511,17 +511,19 @@ void QQuickVisualDataModel::cancel(int index) Compositor::iterator it = d->m_compositor.find(d->m_compositorGroup, index); QQuickVisualDataModelItem *cacheItem = it->inCache() ? d->m_cache.at(it.cacheIndex) : 0; if (cacheItem) { - if (cacheItem->incubationTask) { + if (cacheItem->incubationTask && !cacheItem->isObjectReferenced()) { d->releaseIncubator(cacheItem->incubationTask); cacheItem->incubationTask = 0; - } - if (cacheItem->object && !cacheItem->isObjectReferenced()) { - QObject *object = cacheItem->object; - cacheItem->destroyObject(); - if (QQuickItem *item = qmlobject_cast(object)) - d->emitDestroyingItem(item); - else if (QQuickPackage *package = qmlobject_cast(object)) - d->emitDestroyingPackage(package); + + if (cacheItem->object) { + QObject *object = cacheItem->object; + cacheItem->destroyObject(); + if (QQuickItem *item = qmlobject_cast(object)) + d->emitDestroyingItem(item); + else if (QQuickPackage *package = qmlobject_cast(object)) + d->emitDestroyingPackage(package); + } + cacheItem->scriptRef -= 1; } if (!cacheItem->isReferenced()) {