summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qml.pri2
-rw-r--r--src/declarative/qml/qmlcleanup.cpp82
-rw-r--r--src/declarative/qml/qmlcleanup_p.h79
-rw-r--r--src/declarative/qml/qmlengine.cpp11
-rw-r--r--src/declarative/qml/qmlengine_p.h4
-rw-r--r--src/declarative/qml/qmlintegercache.cpp10
-rw-r--r--src/declarative/qml/qmlintegercache_p.h7
-rw-r--r--src/declarative/qml/qmlpropertycache.cpp14
-rw-r--r--src/declarative/qml/qmlpropertycache_p.h8
-rw-r--r--src/declarative/qml/qmltypenamecache.cpp10
-rw-r--r--src/declarative/qml/qmltypenamecache_p.h6
11 files changed, 224 insertions, 9 deletions
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index b6e86a8..cbc2f85 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -37,6 +37,7 @@ SOURCES += qml/qmlparser.cpp \
qml/qmetaobjectbuilder.cpp \
qml/qmlwatcher.cpp \
qml/qmlscript.cpp \
+ qml/qmlcleanup.cpp \
qml/qmlpropertycache.cpp \
qml/qmlintegercache.cpp \
qml/qmltypenamecache.cpp \
@@ -100,6 +101,7 @@ HEADERS += qml/qmlparser_p.h \
qml/qmlsqldatabase_p.h \
qml/qmetaobjectbuilder_p.h \
qml/qmlwatcher_p.h \
+ qml/qmlcleanup_p.h \
qml/qmlpropertycache_p.h \
qml/qmlintegercache_p.h \
qml/qmltypenamecache_p.h \
diff --git a/src/declarative/qml/qmlcleanup.cpp b/src/declarative/qml/qmlcleanup.cpp
new file mode 100644
index 0000000..7799cfc
--- /dev/null
+++ b/src/declarative/qml/qmlcleanup.cpp
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmlcleanup_p.h"
+#include <private/qmlengine_p.h>
+
+/*!
+\internal
+\class QmlCleanup
+\brief The QmlCleanup provides a callback when a QmlEngine is deleted.
+
+Any object that needs cleanup to occur before the QmlEngine's QScriptEngine is
+destroyed should inherit from QmlCleanup. The clear() virtual method will be
+called by QmlEngine just before it deletes the QScriptEngine.
+*/
+
+/*!
+\internal
+
+Create a QmlCleanup for \a engine
+*/
+QmlCleanup::QmlCleanup(QmlEngine *engine)
+: prev(0), next(0)
+{
+ Q_ASSERT(engine);
+ QmlEnginePrivate *p = QmlEnginePrivate::get(engine);
+
+ if (p->cleanup) next = p->cleanup;
+ p->cleanup = this;
+ prev = &p->cleanup;
+ if (next) next->prev = &next;
+}
+
+/*!
+\internal
+*/
+QmlCleanup::~QmlCleanup()
+{
+ if (prev) *prev = next;
+ if (next) next->prev = prev;
+ prev = 0;
+ next = 0;
+}
+
diff --git a/src/declarative/qml/qmlcleanup_p.h b/src/declarative/qml/qmlcleanup_p.h
new file mode 100644
index 0000000..e9196a3
--- /dev/null
+++ b/src/declarative/qml/qmlcleanup_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLCLEANUP_P_H
+#define QMLCLEANUP_P_H
+
+#include <QtCore/qglobal.h>
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+QT_BEGIN_NAMESPACE
+
+class QmlEngine;
+class QmlCleanup
+{
+public:
+ QmlCleanup(QmlEngine *);
+ virtual ~QmlCleanup();
+
+protected:
+ virtual void clear() = 0;
+
+private:
+ friend class QmlEnginePrivate;
+ QmlCleanup **prev;
+ QmlCleanup *next;
+};
+
+QT_END_NAMESPACE
+
+#endif // QMLCLEANUP_P_H
+
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 354114a..4f3b2ba 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -128,7 +128,7 @@ static QString userLocalDataPath(const QString& app)
QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
: rootContext(0), currentExpression(0),
isDebugging(false), contextClass(0), objectClass(0), valueTypeClass(0), globalClass(0),
- nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), scriptEngine(this),
+ nodeListClass(0), namedNodeMapClass(0), sqlQueryClass(0), cleanup(0), scriptEngine(this),
componentAttacheds(0), rootComponent(0), networkAccessManager(0), typeManager(e), uniqueId(1)
{
QScriptValue qtObject =
@@ -168,6 +168,15 @@ QmlEnginePrivate::QmlEnginePrivate(QmlEngine *e)
QmlEnginePrivate::~QmlEnginePrivate()
{
+ while (cleanup) {
+ QmlCleanup *c = cleanup;
+ cleanup = c->next;
+ if (cleanup) cleanup->prev = &cleanup;
+ c->next = 0;
+ c->prev = 0;
+ c->clear();
+ }
+
delete rootContext;
rootContext = 0;
delete contextClass;
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index a74854d..29621c0 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -97,6 +97,7 @@ class QmlTypeNameScriptClass;
class QmlTypeNameCache;
class QmlComponentAttached;
class QmlListScriptClass;
+class QmlCleanup;
class QmlEnginePrivate : public QObjectPrivate
{
@@ -139,6 +140,9 @@ public:
// Used by SQL database API
QScriptClass *sqlQueryClass;
+ // Registered cleanup handlers
+ QmlCleanup *cleanup;
+
struct QmlScriptEngine : public QScriptEngine
{
QmlScriptEngine(QmlEnginePrivate *priv)
diff --git a/src/declarative/qml/qmlintegercache.cpp b/src/declarative/qml/qmlintegercache.cpp
index 89a18a1..06955c7 100644
--- a/src/declarative/qml/qmlintegercache.cpp
+++ b/src/declarative/qml/qmlintegercache.cpp
@@ -46,13 +46,21 @@
QT_BEGIN_NAMESPACE
QmlIntegerCache::QmlIntegerCache(QmlEngine *e)
-: engine(e)
+: QmlCleanup(e), engine(e)
{
}
QmlIntegerCache::~QmlIntegerCache()
{
+ clear();
+}
+
+void QmlIntegerCache::clear()
+{
qDeleteAll(stringCache);
+ stringCache.clear();
+ identifierCache.clear();
+ engine = 0;
}
void QmlIntegerCache::add(const QString &id, int value)
diff --git a/src/declarative/qml/qmlintegercache_p.h b/src/declarative/qml/qmlintegercache_p.h
index e11e0be..6e9fadd 100644
--- a/src/declarative/qml/qmlintegercache_p.h
+++ b/src/declarative/qml/qmlintegercache_p.h
@@ -55,13 +55,14 @@
#include <private/qmlrefcount_p.h>
#include <private/qscriptdeclarativeclass_p.h>
+#include <private/qmlcleanup_p.h>
#include <QtCore/qhash.h>
QT_BEGIN_NAMESPACE
class QmlType;
class QmlEngine;
-class QmlIntegerCache : public QmlRefCount
+class QmlIntegerCache : public QmlRefCount, public QmlCleanup
{
public:
QmlIntegerCache(QmlEngine *);
@@ -73,6 +74,10 @@ public:
inline int value(const QScriptDeclarativeClass::Identifier &id) const;
static QmlIntegerCache *createForEnums(QmlType *, QmlEngine *);
+
+protected:
+ virtual void clear();
+
private:
struct Data : public QScriptDeclarativeClass::PersistentIdentifier {
Data(const QScriptDeclarativeClass::PersistentIdentifier &i, int v)
diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp
index e00126f..3ede341 100644
--- a/src/declarative/qml/qmlpropertycache.cpp
+++ b/src/declarative/qml/qmlpropertycache.cpp
@@ -86,12 +86,18 @@ void QmlPropertyCache::Data::load(const QMetaMethod &m)
}
-QmlPropertyCache::QmlPropertyCache()
+QmlPropertyCache::QmlPropertyCache(QmlEngine *engine)
+: QmlCleanup(engine)
{
}
QmlPropertyCache::~QmlPropertyCache()
{
+ clear();
+}
+
+void QmlPropertyCache::clear()
+{
for (int ii = 0; ii < indexCache.count(); ++ii)
indexCache.at(ii)->release();
@@ -102,6 +108,10 @@ QmlPropertyCache::~QmlPropertyCache()
for (IdentifierCache::ConstIterator iter = identifierCache.begin();
iter != identifierCache.end(); ++iter)
(*iter)->release();
+
+ indexCache.clear();
+ stringCache.clear();
+ identifierCache.clear();
}
QmlPropertyCache::Data QmlPropertyCache::create(const QMetaObject *metaObject,
@@ -141,7 +151,7 @@ QmlPropertyCache *QmlPropertyCache::create(QmlEngine *engine, const QMetaObject
Q_ASSERT(engine);
Q_ASSERT(metaObject);
- QmlPropertyCache *cache = new QmlPropertyCache;
+ QmlPropertyCache *cache = new QmlPropertyCache(engine);
QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine);
diff --git a/src/declarative/qml/qmlpropertycache_p.h b/src/declarative/qml/qmlpropertycache_p.h
index 91b0c53..6c3142a 100644
--- a/src/declarative/qml/qmlpropertycache_p.h
+++ b/src/declarative/qml/qmlpropertycache_p.h
@@ -55,16 +55,17 @@
#include <private/qmlrefcount_p.h>
#include <private/qscriptdeclarativeclass_p.h>
+#include <private/qmlcleanup_p.h>
#include <QtCore/qvector.h>
QT_BEGIN_NAMESPACE
class QmlEngine;
class QMetaProperty;
-class QmlPropertyCache : public QmlRefCount
+class QmlPropertyCache : public QmlRefCount, public QmlCleanup
{
public:
- QmlPropertyCache();
+ QmlPropertyCache(QmlEngine *);
virtual ~QmlPropertyCache();
struct Data {
@@ -112,6 +113,9 @@ public:
Data *property(const QString &) const;
Data *property(int) const;
+protected:
+ virtual void clear();
+
private:
struct RData : public Data, public QmlRefCount {
QScriptDeclarativeClass::PersistentIdentifier identifier;
diff --git a/src/declarative/qml/qmltypenamecache.cpp b/src/declarative/qml/qmltypenamecache.cpp
index aa1c938..d706c63 100644
--- a/src/declarative/qml/qmltypenamecache.cpp
+++ b/src/declarative/qml/qmltypenamecache.cpp
@@ -45,13 +45,21 @@
QT_BEGIN_NAMESPACE
QmlTypeNameCache::QmlTypeNameCache(QmlEngine *e)
-: engine(e)
+: QmlCleanup(e), engine(e)
{
}
QmlTypeNameCache::~QmlTypeNameCache()
{
+ clear();
+}
+
+void QmlTypeNameCache::clear()
+{
qDeleteAll(stringCache);
+ stringCache.clear();
+ identifierCache.clear();
+ engine = 0;
}
void QmlTypeNameCache::add(const QString &name, QmlType *type)
diff --git a/src/declarative/qml/qmltypenamecache_p.h b/src/declarative/qml/qmltypenamecache_p.h
index f11fe68..ec1e79d 100644
--- a/src/declarative/qml/qmltypenamecache_p.h
+++ b/src/declarative/qml/qmltypenamecache_p.h
@@ -55,12 +55,13 @@
#include <private/qmlrefcount_p.h>
#include <private/qscriptdeclarativeclass_p.h>
+#include <private/qmlcleanup_p.h>
QT_BEGIN_NAMESPACE
class QmlType;
class QmlEngine;
-class QmlTypeNameCache : public QmlRefCount
+class QmlTypeNameCache : public QmlRefCount, public QmlCleanup
{
public:
QmlTypeNameCache(QmlEngine *);
@@ -79,6 +80,9 @@ public:
Data *data(const QString &) const;
inline Data *data(const QScriptDeclarativeClass::Identifier &id) const;
+protected:
+ virtual void clear();
+
private:
struct RData : public Data {
QScriptDeclarativeClass::PersistentIdentifier identifier;