History

Clean out updateMemoryCost

Zach Pomerantz committed 10 years ago

Commit 854c0ea1 parent 1e8d45a3 files · +24 −10Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 3 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+11−1
@@ -274,7 +274,17 @@ static void resultHandlerFromScriptValue(const QScriptValue& value, AnimVariantR · 273 unmodified lines
274274 using ScriptableResourceRawPtr = ScriptableResource*;
275275
276276 static QScriptValue scriptableResourceToScriptValue(QScriptEngine* engine, const ScriptableResourceRawPtr& resource) {
277− resource->updateMemoryCost(engine);
277+ // The first script to encounter this resource will track its memory.
278+ // In this way, it will be more likely to GC.
279+ // This fails in the case that the resource is used across many scripts, but
280+ // in that case it would be too difficult to tell which one should track the memory, and
281+ // this serves the common case (use in a single script).
282+ auto data = resource->getResource();
283+ if (data && !resource->isInScript()) {
284+ resource->setInScript(true);
285+ QObject::connect(data.data(), SIGNAL(updateSize(qint64)), engine, SLOT(updateMemoryCost(qint64)));
286+ }
287+
278288 auto object = engine->newQObject(
279289 const_cast<ScriptableResourceRawPtr>(resource),
280290 QScriptEngine::ScriptOwnership);