aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlengine
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2012-04-19 14:38:38 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-27 10:38:58 +0200
commitb765e3a84bc531878a5cc0d451451a94565b13f8 (patch)
tree4c506d229c76924a2c72de31464efa8b440f005f /tests/auto/qml/qqmlengine
parent7ec674ee9a8e51cb1cb7ef60b1d27845349b8dec (diff)
Avoid calling gc in QQmlEngine destructor.
GC may be expensive. GC call in QQmlEngine doesn't have much sense because V8 will destroy all objects living in a current context. The only problem is that V8 may decide to not invoke weak callbacks which may cause a memory leak. To avoid that we track all QObjects that have JavaScript ownership set and we delete them explicitly. The change reduce time of destroying QQmlEngine by 75%, which is really visible in qquicklistmodel test. Change-Id: I2a3668fd23630669114baee8c241a7ecc4100e33 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlengine')
-rw-r--r--tests/auto/qml/qqmlengine/tst_qqmlengine.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
index c039429f48..ab18cdd050 100644
--- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
+++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
@@ -46,6 +46,7 @@
#include <QPointer>
#include <QDir>
#include <QStandardPaths>
+#include <QSignalSpy>
#include <QDebug>
#include <QQmlComponent>
#include <QQmlNetworkAccessManagerFactory>
@@ -67,6 +68,13 @@ private slots:
void outputWarningsToStandardError();
void objectOwnership();
void multipleEngines();
+
+public slots:
+ QObject *createAQObjectForOwnershipTest ()
+ {
+ static QObject *ptr = new QObject();
+ return ptr;
+ }
};
void tst_qqmlengine::rootContext()
@@ -326,7 +334,37 @@ void tst_qqmlengine::objectOwnership()
delete o;
}
-
+ {
+ QObject *ptr = createAQObjectForOwnershipTest();
+ QSignalSpy spy(ptr, SIGNAL(destroyed()));
+ {
+ QQmlEngine engine;
+ QQmlComponent c(&engine);
+ engine.rootContext()->setContextProperty("test", this);
+ QQmlEngine::setObjectOwnership(ptr, QQmlEngine::JavaScriptOwnership);
+ c.setData("import QtQuick 2.0; Item { property int data: test.createAQObjectForOwnershipTest() ? 0 : 1 }", QUrl());
+ QVERIFY(c.isReady());
+ QObject *o = c.create();
+ QVERIFY(o != 0);
+ }
+ QTRY_VERIFY(spy.count());
+ }
+ {
+ QObject *ptr = new QObject();
+ QSignalSpy spy(ptr, SIGNAL(destroyed()));
+ {
+ QQmlEngine engine;
+ QQmlComponent c(&engine);
+ engine.rootContext()->setContextProperty("test", ptr);
+ QQmlEngine::setObjectOwnership(ptr, QQmlEngine::JavaScriptOwnership);
+ c.setData("import QtQuick 2.0; QtObject { property var object: { var i = test; test ? 0 : 1 } }", QUrl());
+ QVERIFY(c.isReady());
+ QObject *o = c.create();
+ QVERIFY(o != 0);
+ engine.rootContext()->setContextProperty("test", 0);
+ }
+ QTRY_VERIFY(spy.count());
+ }
}
// Test an object can be accessed by multiple engines