Bug 422755 - Memory leak in plasmashell on opening activity manager sidebar repeatedly
Summary: Memory leak in plasmashell on opening activity manager sidebar repeatedly
Status: CONFIRMED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Activity Switcher (show other bugs)
Version: 5.19.0
Platform: Other Linux
: NOR normal
Target Milestone: 1.0
Assignee: Ivan Čukić
URL:
Keywords: efficiency
Depends on:
Blocks:
 
Reported: 2020-06-10 15:21 UTC by Kishore Gopalakrishnan
Modified: 2021-12-08 01:16 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Output of valgrind on repeadtedly triggering the activity manager sidebar (590.60 KB, application/x-valgrind-massif)
2021-03-21 09:33 UTC, Kishore Gopalakrishnan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kishore Gopalakrishnan 2020-06-10 15:21:09 UTC
SUMMARY
If we repeatedly open the activity manager sidebar (the one that shows a list of activities and allows you to suspend or resume them) Plasma's memory usage increases without bound. The consumed memory does not seem to be freed even 30 minutes later. This is also reproducible by repeatedly opening and closing popups in the system tray.

STEPS TO REPRODUCE
1. Open a Konsole window (to run the script) and a Ksysguard window (to monitor Plasma's memory usage)
2. Note the initial memory usage of the plasmashell process.
3. Run the following script in bash:
```
while true
do
	sleep 0.1
	qdbus org.kde.plasmashell /PlasmaShell toggleActivityManager
done
```

OBSERVED RESULT
Note that the memory keeps on increasing without bound. After perhaps 10 minutes, the memory usage is a few 100 MB greater than the initial value (I have observed it easily crossing 500 MB). If you kill the script, wait, and look at Plasma's memory usage after some time, you will still see that it is >= the value it had when you killed the script.

EXPECTED RESULT
Memory usage should not increase without bound. Even if it increases, it should at least be freed after some time.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.19.0
KDE Frameworks Version: 5.70.0
Qt Version: 5.15.0
Kernel Version: 5.6.15-arch1-1
Display server: X
Compositor rendering backend: Opengl 2.0
Graphics driver: amdgpu

HARDWARE INFORMATION
OS Type: 64-bit
Processors: 8 × AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
Memory: 13.6 GiB of RAM
Graphics Processor: AMD RAVEN 

ADDITIONAL INFORMATION
I often observe that after a week or so of uptime, plasmashell's memory usage can be close to a GB, which may be due to the same underlying cause. You can also reproduce this same issue by repeatedly clicking on system tray applets for many minutes, but I have reported for the activities manager as is was the first thing I was able to figure out how to activate from a script. I was also able to reproduce this in a different user account with the default theme, window decorations, etc.

POSSIBLE DUPLICATES
bug 412865
bug 393929
Comment 1 Alex 2020-06-16 05:28:53 UTC
I'm able to reproduce this on Fedora 32 with Plasma 5.18.5, Frameworks 5.70.0 and Qt 5.14.2
Comment 2 Alex 2020-06-16 05:32:38 UTC
I should add that I'm also on an X11 session on amdgpu, but I could still reproduce this with the compositor toggled off (alt+shift+f12).
Comment 3 Kishore Gopalakrishnan 2020-06-16 14:30:50 UTC
I can reproduce this in a Wayland session as well. 

In X11, setting `export QSG_RENDER_LOOP="basic"` in `~/.xprofile` (suggested on some other reports of memory leaks) does not help.
Comment 4 Kishore Gopalakrishnan 2021-03-21 09:33:52 UTC
Created attachment 136910 [details]
Output of valgrind on repeadtedly triggering the activity manager sidebar

Hi, I am attaching the valgrind output from a run of plasmashell. On opening it in Massif-Visualizer, I can see a linear growth of heap memory under `QObjectPrivate::connectImpl(QObject const*, int, QObject const*, void**, QtPrivate::QSlotObjectBase*, Qt::ConnectionType, int const*, QMetaObject const*) (qobject.cpp:5050)`. Hopefully this is useful to find out the root cause of this bug. 

Here are the steps I used to generate this file:
```
kquitapp5 plasmashell #Kill already running plasmashell
valgrind --tool=massif plasmashell
#Do stuff to trigger the memory leak (run the script in my report for a while or just click around on various widgets)
kquitapp5 plasmashell #Kill plasmashell after some time.
```
In case you want me to compile any other packages with debug symbols or pass any other options to valgrind, please let me know.
Comment 5 Kishore Gopalakrishnan 2021-03-28 11:32:23 UTC
Here is the heaptrack output (64MB file; I didn't pass any special options to heaptrack), after repeatedly opening the activity manager for about 20 min. It shows a huge leak in "QImageData::create". Not sure how helpful this is.

https://drive.google.com/file/d/14qCFKkS8L8Own7NVCbOiXSN3Ji_VLitx/view?usp=sharing
Comment 6 Alex 2021-05-09 03:46:24 UTC
In Plasma 5.21.4, Qt 5.15.2, Frameworks 5.80, on a Wayland session in Fedora 34, I can successfully reproduce this leak with that bash script. Maybe this is a Qt bug, not sure, but since it does occur, I'll mark it as confirmed.
Comment 7 Iyán Méndez Veiga 2021-10-22 19:26:12 UTC
I cannot reproduce this on two different computers:

Desktop PC
Operating System: Arch Linux
KDE Plasma Version: 5.23.1
KDE Frameworks Version: 5.87.0
Qt Version: 5.15.2
Kernel Version: 5.14.14-arch1-1 (64-bit)
Graphics Platform: X11
Processors: 8 × Intel® Core™ i7-4790K CPU @ 4.00GHz
Memory: 15.5 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 1070/PCIe/SSE2

Laptop
Operating System: Arch Linux
KDE Plasma Version: 5.23.1
KDE Frameworks Version: 5.87.0
Qt Version: 5.15.2
Kernel Version: 5.14.14-arch1-1 (64-bit)
Graphics Platform: X11
Processors: 8 × 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz
Memory: 15.4 GiB of RAM
Graphics Processor: Mesa Intel® Xe Graphics
Comment 8 Fushan Wen 2021-12-02 07:17:46 UTC
I cannot reproduce it in an X11 session on amdgpu either. Could be a driver bug.

Can the bug still be reproduced today?
Comment 9 Alex 2021-12-02 07:52:33 UTC
I can still reproduce this bug on Plasma 5.23.3, Fedora 35. Maybe this is Wayland-exclusive. I will give this the wayland keyword.
Comment 10 Kishore Gopalakrishnan 2021-12-04 16:31:43 UTC
I can reproduce this on X11 (this is in a VM; will test on my main machine tomorrow):

Operating System: Arch Linux
KDE Plasma Version: 5.23.4
KDE Frameworks Version: 5.88.0
Qt Version: 5.15.2
Kernel Version: 5.10.83-1-lts (64-bit)
Graphics Platform: X11
Processors: 4 × AMD EPYC-Rome Processor
Memory: 1.4 GiB of RAM
Graphics Processor: virgl
Comment 11 Kishore Gopalakrishnan 2021-12-05 11:45:45 UTC
I can still reproduce this on a machine that uses amdgpu. Plasmashell's memory consumption went from 150 MB to 650 MB in 40 minutes when I left the loop from the initial comment running.

Operating System: Arch Linux
KDE Plasma Version: 5.23.4
KDE Frameworks Version: 5.88.0
Qt Version: 5.15.2
Kernel Version: 5.15.6-arch2-1 (64-bit)
Graphics Platform: X11
Processors: 8 × AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
Memory: 21.5 GiB of RAM
Graphics Processor: AMD Radeon Vega 8 Graphics