diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-10-19 16:07:54 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-10-21 16:29:11 +0000 |
commit | d62437be7743bbb5d7697bf2d3bf4b74cc79223e (patch) | |
tree | ce9643fbdca368be164defe64f3cdb2c96ac4008 /src/quick/items | |
parent | fc95c09b06ff6dcdf72511a06c3c64bfc59261f1 (diff) |
qquickloader: Free memory of loaded components after source change
Since we cannot be sure when the event loop that would usually
handle deferred deletions will run the next time we have to delete these
components immediately otherwise we might run out of memory.
Fixes: QTBUG-86676
Done-with: Maximilian Goldstein <max.goldstein@qt.io>
Change-Id: I01d74f7eea442f8ba240dd66a4cedd6316fbeec2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit c5085eb8905f1a3c070f866746110980e84be271)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquickloader.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp index 8cd63a4236..9a8eca871c 100644 --- a/src/quick/items/qquickloader.cpp +++ b/src/quick/items/qquickloader.cpp @@ -412,6 +412,19 @@ void QQuickLoader::setSource(const QUrl &url) void QQuickLoader::setSource(const QUrl &url, bool needsClear) { Q_D(QQuickLoader); + + // The source has been changed at this point, and we assume that (after + // notifying potential listeners with sourceChanged) that it is now + // safe to actually delete the old component. We have to do this here + // in case the component referenced expensive resources (like uncached + // images), as it might take too long until we return to the event loop. + // We need to explicitly pass QEvent::DeferredDelete to sendPostedEvents, + // else the allowDeferredDelete check in qcoreapplication.cpp will not + // allow the event to pass. This will not affect anything deleted by this + // call, only the previous one. This has to be done as otherwise there + // might be signal handlers that are still in progress. + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + if (d->source == url) return; |