summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-03-25 13:45:51 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-03-25 14:05:13 (GMT)
commit2fdfb3e0285ac535b63548d208da6dcae71105cc (patch)
tree4072a9c4cbc3ce49af779143f44776bdaf0c4f59 /tests
parent062af5a146e4875ace293823452347a572eda14f (diff)
downloadQt-2fdfb3e0285ac535b63548d208da6dcae71105cc.zip
Qt-2fdfb3e0285ac535b63548d208da6dcae71105cc.tar.gz
Qt-2fdfb3e0285ac535b63548d208da6dcae71105cc.tar.bz2
QtScript: Add API for reporting additional memory costs
QScriptEngine::reportAdditionalMemoryCost(int). This function provides the ability to give a hint to the engine that it should perhaps trigger garbage collection sooner rather than later. For example, if you've implemented a JS ByteArray class that wraps a QByteArray, and a user constructs a few hundred temporary ByteArray objects of large sizes, failure to report the additional memory cost may cause the application's memory consumption to grow and grow (because the script engine thinks they are "cheap" objects, the GC won't kick in). Reporting the correct size can be difficult (or impossible) in some cases. For example, it's difficult to predict the total amount of system memory & resources consumed by a QImage. But even reporting a heuristic / approximate cost can be better than reporting no cost. Task-number: QTBUG-6238 Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index e71d7c3..0615b63 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -121,6 +121,7 @@ private slots:
void castWithPrototypeChain();
void castWithMultipleInheritance();
void collectGarbage();
+ void reportAdditionalMemoryCost();
void gcWithNestedDataStructure();
void processEventsWhileRunning();
void throwErrorFromProcessEvents();
@@ -2369,6 +2370,24 @@ void tst_QScriptEngine::collectGarbage()
QVERIFY(ptr == 0);
}
+void tst_QScriptEngine::reportAdditionalMemoryCost()
+{
+ QScriptEngine eng;
+ for (int x = 0; x < 1000; ++x) {
+ eng.reportAdditionalMemoryCost(0);
+ eng.reportAdditionalMemoryCost(10);
+ eng.reportAdditionalMemoryCost(1000);
+ eng.reportAdditionalMemoryCost(10000);
+ eng.reportAdditionalMemoryCost(100000);
+ eng.reportAdditionalMemoryCost(1000000);
+ eng.reportAdditionalMemoryCost(10000000);
+ eng.reportAdditionalMemoryCost(-1);
+ eng.reportAdditionalMemoryCost(-1000);
+ QScriptValue obj = eng.newObject();
+ eng.collectGarbage();
+ }
+}
+
void tst_QScriptEngine::gcWithNestedDataStructure()
{
QScriptEngine eng;