Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
Description
Background
Gradients used in Qt Quick Shapes are cached unconditionally: https://github.com/qt/qtdeclarative/blob/v6.9.0/src/quick/scenegraph/util/qsggradientcache.cpp#L69-L118
Problem
Once a gradient texture enters the cache, it stays there quite permanently (well, at least it's deleted if the owning window is deleted, but this doesn't normally happen in embedded systems).
In the example app below, dragging the slider will noticeably increase memory consumption (visible via the Windows Task Manager, for example), with no easy way to bring it down:
import QtQuick import QtQuick.Shapes import QtQuick.Controls.Basic ApplicationWindow { id: root width: 640 height: 480 visible: true property real radius: 200 header: Slider { id: hueSlider from: 0 to: 1 } Shape { x: root.radius y: root.radius width: root.radius * 2 height: root.radius * 2 ShapePath { strokeWidth: 0 PathAngleArc { radiusX: root.radius radiusY: root.radius startAngle: 0 sweepAngle: 360 } fillGradient: ConicalGradient { GradientStop { position: 0; color: "transparent" } GradientStop { position: 0.5; color: Qt.hsva(hueSlider.value, 1, 1, 1) } GradientStop { position: 1; color: "transparent" } } } } }
A customer's real app, which has animating gradients, crashed from running out of memory.
Workarounds
- Currently, we do have an API to clear the entire cache associated with a scene, e.g. quickWindow->rhi()->runCleanup();. However, this is a "nuclear" option that deletes all gradients (including those that are still needed), and it has to be done from C++.
- Use the old Qt 5 Graphical Effects (e.g. https://doc.qt.io/qt-6/qml-qt5compat-graphicaleffects-conicalgradient.html ) which apply shader effects instead of cached textures.
Suggestions
- Follow the footsteps of QQuickPixmapCache. It has a cache_limit and a mechanism to drop the oldest, unused pixmaps from the cache to stay within the limit: https://github.com/qt/qtdeclarative/blob/v6.9.0/src/quick/util/qquickpixmapcache.cpp#L1348
- Follow the footsteps of Qt 5 Graphical Effects. It allowed users to disable cacheing for selected gradients: https://doc.qt.io/qt-6/qml-qt5compat-graphicaleffects-conicalgradient.html#cached-prop