Possible memory leak of gradient animation
-
Hi everyone,
I have such an animation:
Mem_leak.gif
But it changes duration every time and because of that memory usage grows and grows.
It eats RAM either under Qt 5.15.12 and Qt 6.6.1.
When I wrote this post it grew from 80 MB till 300 MB
Is it a bug to call or there is some misuse on my side?
Below is the code (sorry for long example but complexity ofPathSvg
matters :import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Shapes 1.15 Window { id: pathWin width: 1366; height: 768 color: "#bbb" property real grAnim: 0.0 property int animDur: 2000 NumberAnimation { id: goAnim running: true target: pathWin property: "grAnim" from: 0; to: 1 duration: animDur onFinished: { animDur = 500 + Math.random() * 10000 backAnim.start() } } NumberAnimation { id: backAnim target: pathWin property: "grAnim" from: 1; to: 0 duration: animDur onFinished: { animDur = 500 + Math.random() * 10000 goAnim.start() } } Shape { width: 269; height: 356 antialiasing: true smooth: true rotation: 180; scale: 1.5 ShapePath { strokeColor: "#777" strokeWidth: 2 fillGradient: LinearGradient { x1: 134.5; y1: -400; x2: 134.5; y2: 400 GradientStop { position: 0.0; color: "#005500" } GradientStop { position: grAnim * 0.9; color: "#005500" } GradientStop { position: 0.1 + grAnim * 0.9; color: "#AAA" } } PathSvg { //path: "" // quite complex path } } } }
-
Hi everyone,
I have such an animation:
Mem_leak.gif
But it changes duration every time and because of that memory usage grows and grows.
It eats RAM either under Qt 5.15.12 and Qt 6.6.1.
When I wrote this post it grew from 80 MB till 300 MB
Is it a bug to call or there is some misuse on my side?
Below is the code (sorry for long example but complexity ofPathSvg
matters :import QtQuick 2.15 import QtQuick.Window 2.15 import QtQuick.Shapes 1.15 Window { id: pathWin width: 1366; height: 768 color: "#bbb" property real grAnim: 0.0 property int animDur: 2000 NumberAnimation { id: goAnim running: true target: pathWin property: "grAnim" from: 0; to: 1 duration: animDur onFinished: { animDur = 500 + Math.random() * 10000 backAnim.start() } } NumberAnimation { id: backAnim target: pathWin property: "grAnim" from: 1; to: 0 duration: animDur onFinished: { animDur = 500 + Math.random() * 10000 goAnim.start() } } Shape { width: 269; height: 356 antialiasing: true smooth: true rotation: 180; scale: 1.5 ShapePath { strokeColor: "#777" strokeWidth: 2 fillGradient: LinearGradient { x1: 134.5; y1: -400; x2: 134.5; y2: 400 GradientStop { position: 0.0; color: "#005500" } GradientStop { position: grAnim * 0.9; color: "#005500" } GradientStop { position: 0.1 + grAnim * 0.9; color: "#AAA" } } PathSvg { //path: "" // quite complex path } } } }
-
@SeeLook this is just a wild guess, but...what happens if you remove the randomness from the durations? I'm wondering whether it's trying to cache some portion of your objects, but because the randomness makes each one different, it can't reuse them.
-
So far it seems not like a bug but intended caching.
I tried to remove/create this tree path every time the animation starts but no RAM is released:property var tree: Qt.createComponent("TreeShape.qml").createObject(pathWin) NumberAnimation { id: goAnim running: true target: pathWin property: "grAnim" from: 0; to: 1 duration: animDur onFinished: { animDur = 500 + Math.random() * 10000 tree.destroy() tree = Qt.createComponent("TreeShape.qml").createObject(pathWin) backAnim.start() } }
So maybe it would be more proper to ask how to clean this cache?
-
So far it seems not like a bug but intended caching.
I tried to remove/create this tree path every time the animation starts but no RAM is released:property var tree: Qt.createComponent("TreeShape.qml").createObject(pathWin) NumberAnimation { id: goAnim running: true target: pathWin property: "grAnim" from: 0; to: 1 duration: animDur onFinished: { animDur = 500 + Math.random() * 10000 tree.destroy() tree = Qt.createComponent("TreeShape.qml").createObject(pathWin) backAnim.start() } }
So maybe it would be more proper to ask how to clean this cache?
-
@SeeLook from your description, this doesn't really seem like a true memory leak; it's more just a really memory-intensive application. I'm assuming that once it hits the 300 MB mark, it remains relatively steady?
@mzimmers
Unfortunately not.
The app is working on 1GB device and it crashes after 30 min of work exactly because of this kind of animation.
So I'm looking for solution.
If there is no simpler way, maybe I will try to implement that in C++ usingQQuickPainedItem
. -
@mzimmers
Unfortunately not.
The app is working on 1GB device and it crashes after 30 min of work exactly because of this kind of animation.
So I'm looking for solution.
If there is no simpler way, maybe I will try to implement that in C++ usingQQuickPainedItem
. -
@jsulm
Ok. Let's try. But please help me to interpret it:
memAtPeak.png
I can see that
QQuickShapeGradientOpenGlCache
takes 16 MB at peak but only 357 KiB at start.
Shall I share this massif tool dumped data? -
@jsulm
After about 20 min.
massif_20min.png
.. and probably it would grow and growHere is full massif file
@SeeLook Could be a bug in Qt. You can file a bug at https://bugreports.qt.io/secure/Dashboard.jspa
-
The problem is that every unique value of
grAnim
causes a new texture to be generated and stored in the cache: https://bugreports.qt.io/browse/QTBUG-136553