aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvme.cpp
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-05-04 08:32:45 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-17 08:58:45 +0200
commit43a6cc75886c662e63db440dd191cefa1fe956f3 (patch)
treecd3247453a0c2a59e0c5d3af11434d18761c2de4 /src/qml/qml/qqmlvme.cpp
parent9af1a7d0aee4f9ed48b2519779388830a8dd03e9 (diff)
Add QQmlEngine::trimComponentCache()
Allow unused data in the engine's component cache to be safely discarded so that the memory can be freed for other purposes. Unloading of scripts that are no longer required after trimming unused components is not yet supported. Task-number: QTBUG-25653 Change-Id: I37bc9d5592eeb5edceeb34d010a555dcffd11cea Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlvme.cpp')
-rw-r--r--src/qml/qml/qqmlvme.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index 852a682630..ba0f202bcc 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -133,11 +133,11 @@ bool QQmlVME::initDeferred(QObject *object)
{
QQmlData *data = QQmlData::get(object);
- if (!data || !data->context || !data->deferredComponent)
+ if (!data || !data->context || !data->compiledData)
return false;
QQmlContextData *ctxt = data->context;
- QQmlCompiledData *comp = data->deferredComponent;
+ QQmlCompiledData *comp = data->compiledData;
int start = data->deferredIdx;
State initState;
@@ -444,7 +444,7 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
CTXT->setIdPropertyData(COMP->contextCaches.at(instr.contextCache));
if (instr.compiledBinding != -1) {
const char *v4data = DATAS.at(instr.compiledBinding).constData();
- CTXT->v4bindings = new QV4Bindings(v4data, CTXT, COMP);
+ CTXT->v4bindings = new QV4Bindings(v4data, CTXT);
}
if (states.count() == 1) {
rootContext = CTXT;
@@ -515,6 +515,15 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
QQmlData *ddata = QQmlData::get(o);
Q_ASSERT(ddata);
+ if (states.count() == 1) {
+ // Keep a reference to the compiled data we rely on.
+ // Only the top-level component instance needs to add a reference - higher-level
+ // components add a reference to the components they depend on, so an instance
+ // of the top-level component keeps them all referenced.
+ ddata->compiledData = states[0].compiledData;
+ ddata->compiledData->addref();
+ }
+
if (instr.isRoot) {
if (ddata->context) {
Q_ASSERT(ddata->context != CTXT);
@@ -563,6 +572,12 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
VME_EXCEPTION(tr("Unable to create object of type %1").arg(type.type->elementName()),
instr.line);
+ if (states.count() == 1) {
+ // Keep a reference to the compiled data we rely on
+ ddata->compiledData = states[0].compiledData;
+ ddata->compiledData->addref();
+ }
+
if (instr.isRoot) {
if (ddata->context) {
Q_ASSERT(ddata->context != CTXT);
@@ -649,6 +664,12 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
CTXT->addObject(qcomp);
+ if (states.count() == 1) {
+ // Keep a reference to the compiled data we rely on
+ ddata->compiledData = states[0].compiledData;
+ ddata->compiledData->addref();
+ }
+
if (instr.isRoot)
ddata->ownContext = true;
@@ -673,7 +694,7 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
const QQmlVMEMetaData *data =
(const QQmlVMEMetaData *)DATAS.at(instr.aliasData).constData();
- (void)new QQmlVMEMetaObject(target, &mo, data, COMP);
+ (void)new QQmlVMEMetaObject(target, &mo, data);
if (instr.propertyCache != -1) {
QQmlData *ddata = QQmlData::get(target, true);
@@ -1000,11 +1021,11 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
QML_BEGIN_INSTR(Defer)
if (instr.deferCount) {
QObject *target = objects.top();
- QQmlData *data =
- QQmlData::get(target, true);
- COMP->addref();
- data->deferredComponent = COMP;
+ QQmlData *data = QQmlData::get(target, true);
+ data->compiledData = COMP;
+ data->compiledData->addref(); // Keep this data referenced until we're initialized
data->deferredIdx = INSTRUCTIONSTREAM - COMP->bytecode.constData();
+ Q_ASSERT(data->deferredIdx != 0);
INSTRUCTIONSTREAM += instr.deferCount;
}
QML_END_INSTR(Defer)