diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-19 05:38:14 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-19 05:39:03 (GMT) |
commit | cb54ab7c6f60cadc85c25750a1b2aa3bc96a1505 (patch) | |
tree | 2029f9274ff771e72b55c41b389f803fe5bbca4d | |
parent | 16d2b97e03ff99583ab25977880affecc1c4463b (diff) | |
download | Qt-cb54ab7c6f60cadc85c25750a1b2aa3bc96a1505.zip Qt-cb54ab7c6f60cadc85c25750a1b2aa3bc96a1505.tar.gz Qt-cb54ab7c6f60cadc85c25750a1b2aa3bc96a1505.tar.bz2 |
Reference count ObjectData's to correctly delete objects with no parent
QTBUG-9872
-rw-r--r-- | src/declarative/qml/qdeclarativedata_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 9 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h index 2ddd7e5..4a56536 100644 --- a/src/declarative/qml/qdeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedata_p.h @@ -75,7 +75,7 @@ public: : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), - attachedProperties(0), scriptValue(0), propertyCache(0), guards(0) { + attachedProperties(0), scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0) { init(); } @@ -128,6 +128,7 @@ public: // ### Can we make this QScriptValuePrivate so we incur no additional allocation // cost? QScriptValue *scriptValue; + quint32 objectDataRefCount; QDeclarativePropertyCache *propertyCache; QDeclarativeGuard<QObject> *guards; diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 5773fe6..a27d19d 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -59,12 +59,17 @@ Q_DECLARE_METATYPE(QScriptValue); QT_BEGIN_NAMESPACE struct ObjectData : public QScriptDeclarativeClass::Object { - ObjectData(QObject *o, int t) : object(o), type(t) {} + ObjectData(QObject *o, int t) : object(o), type(t) { + if (o) { + QDeclarativeData *ddata = QDeclarativeData::get(object, true); + if (ddata) ddata->objectDataRefCount++; + } + } virtual ~ObjectData() { if (object && !object->parent()) { QDeclarativeData *ddata = QDeclarativeData::get(object, false); - if (ddata && !ddata->indestructible) + if (ddata && !ddata->indestructible && 0 == --ddata->objectDataRefCount) object->deleteLater(); } } |