aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2025-12-09 14:12:18 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2025-12-10 11:23:56 +0100
commita604a80c649f803c72416d7686ad67220e8822cf (patch)
tree103adb2d16ccd1270b6391c9de32fd11a77e100e /src
parentb185a8dc5986c5af849e4815f8b49fb91ad732c8 (diff)
Qt.createQmlObject: Trim compilation units
When we call createQmlObject, a completely new compilation unit is created. If an object is stil in use, that compilation is obviously needed. However, if code is using createQmlObject repeatedly with the same URL, there's a good chance that the object was only temporarily needed. To avoid unbounded memory usage in that case, we call trimCompilationUnitsForUrl, to remove the no longer needed CUs. Note that this does not help if the URL is also changing dynamically, but we don't want to trim all caches, including ones the user might actually want to hold on. To handle such cases, we should rather 1. integrate the trimming logic with the gc 2. give it a separate, configurable "high water mark" 3. Use some proper caching system for CUs, e.g. LRU That is however out of scope for this commit. Pick-to: 6.11 6.10 6.8 Fixes: QTBUG-142555 Change-Id: I7ebb63abd9bb99531b6b6b2cf1f98b35b1e652e2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/qqmlbuiltinfunctions.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlbuiltinfunctions.cpp b/src/qml/qml/qqmlbuiltinfunctions.cpp
index 9f72241657..3e36e9ea3c 100644
--- a/src/qml/qml/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/qqmlbuiltinfunctions.cpp
@@ -1561,6 +1561,7 @@ QObject *QtObject::createQmlObject(const QString &qml, QObject *parent, const QU
}
component.completeCreate();
+ v4Engine()->trimCompilationUnitsForUrl(resolvedUrl);
if (component.isError()) {
ScopedValue v(scope, Error::create(scope.engine, component.errors()));
scope.engine->throwError(v);