From b26a588c1702a84ba853df3c757d879cc9f2fc46 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 17 May 2012 17:32:15 +1000 Subject: Fix memory leak in qdeclarativevisualdatamodel. Parent order was backwards, the inner context was parented to the outer context, and then the inner context was reparented to the delegate. Parent the outer context to inner context so both are deleted when the delegate is deleted. Task-number: QTBUG-25784 Change-Id: I1d6cd4dfc2530424535a7e00164563d9b4aaa513 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 3f71e57..42a87b9 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -1056,8 +1056,10 @@ QDeclarativeItem *QDeclarativeVisualDataModel::item(int index, const QByteArray QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); if ((!d->m_listModelInterface || !d->m_abstractItemModel) && d->m_listAccessor && d->m_listAccessor->type() == QDeclarativeListAccessor::ListProperty) { - ctxt->setContextObject(d->m_listAccessor->at(index).value()); - ctxt = new QDeclarativeContext(ctxt, ctxt); + QDeclarativeContext *objCtxt = ctxt; + objCtxt->setContextObject(d->m_listAccessor->at(index).value()); + ctxt = new QDeclarativeContext(ctxt); + QDeclarative_setParent_noEvent(objCtxt, ctxt); } ctxt->setContextProperty(QLatin1String("model"), data); ctxt->setContextObject(data); -- cgit v0.12