Bug 501211 - Memory leak when window leaves full-screen 8 times or more
Summary: Memory leak when window leaves full-screen 8 times or more
Status: REOPENED
Alias: None
Product: kwin
Classification: Plasma
Component: performance (other bugs)
Version First Reported In: 6.3.2
Platform: Other Linux
: NOR major
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-08 05:52 UTC by qethanmoore+kde
Modified: 2025-03-31 08:20 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description qethanmoore+kde 2025-03-08 05:52:41 UTC
SUMMARY
When a window toggles full-screen many times, RAM usage attributed to kwin_wayland grows substantially.
Rebooting or kwin_wayland --replace returns RAM usage to normal. Closing all windows does not.

STEPS TO REPRODUCE
1. Open VLC, mpv, Firefox or any other program that can enter full-screen
2. Press the toggle full-screen button (usually F11 or 'f') exactly 16 times to observe the first memory leak and a lag spike
3. Leaving full-screen again (i.e. pressing toggle twice more) will leak much more memory each time

OBSERVED RESULT
Total RAM usage while testing with mpv looked like this:
1.7GiB to start, with video open and playing in a small window
16 full-screen toggles later: the first permanent increase to 1.9GiB
Subsequent times leaving full-screen: 2.5, 4.8, 14.3 GiB
(Going further exhausts my RAM entirely. Only holding the power button has any effect at that point.)

Other runs:
(kwin_wayland --replace)
[1.7,(16 full-screen toggles...) 1.8, 2.4, 4.8, 14.3] GiB
(and after a reboot)
[1.7,(16 full-screen toggles...) 1.9, 2.5, 4.9, 14.4] GiB

EXPECTED RESULT
RAM usage should be stable when a window cycles full-screen any number of times

SOFTWARE/OS VERSIONS
Operating System: EndeavourOS 
KDE Plasma Version: 6.3.2
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.13.5-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 2600X Six-Core Processor
Memory: 15.5 GiB of RAM
Graphics Processor: AMD Radeon RX 580 Series

ADDITIONAL INFORMATION
Closing the window after step 2 will also result in a lag spike.
Pressing alt+F4 before the 16th toggle avoids the problem, even if the window appears to leave full-screen for the problematic 8th time as it closes.
The issue is per window. I can drag a new tab from Firefox out into its own new window and it has the full 16 toggle capacity, independent of its originating window.
Another user has reported similar behaviour in coment 48 of bug id 496469; also an EndeavourOS user, but different hardware.
All other methods of toggling full-screen are affected. I avoided double-clicking videos because counting single key-presses feels more precise. It is always the 16th toggle on my machine measured this way.
Comment 1 Nate Graham 2025-03-11 21:53:43 UTC
I can reproduce this. Repeatedly full-screening LibreWolf (a Firefox fork) and leaving full screen does indeed cause kwin_wayland's memory usage to rise and then not fall again.
Comment 2 qethanmoore+kde 2025-03-12 23:53:14 UTC
I have upgraded my system and the problem is resolved, marking FIXED!

Operating System: EndeavourOS 
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.13.6-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 2600X Six-Core Processor
Memory: 15.5 GiB of RAM
Graphics Processor: AMD Radeon RX 580 Series

Please check the above releases before reopening if you're still having trouble
Comment 3 qethanmoore+kde 2025-03-17 10:30:49 UTC
Oops, I guess I had a few good days, but it's definitely back exactly as it was. Real headscratcher

Operating System: EndeavourOS 
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.12.0
Qt Version: 6.8.2
Kernel Version: 6.13.7-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 2600X Six-Core Processor
Memory: 15.5 GiB of RAM
Graphics Processor: AMD Radeon RX 580 Series
Comment 4 John Kizer 2025-03-28 04:29:33 UTC
For what it's worth, I can't reproduce this on my Fedora KDE 41 device (NVIDIA graphics) or on a KDE Neon VM (QEMU, software rendering).
Comment 5 Nick H 2025-03-30 00:47:01 UTC
Also getting this bug. I'll add full info if that's OK because I reproduce it slightly differently.

SUMMARY
When playing games with external monitor connected, Kwin_Wayland increasingly uses all of the memory until system is at 100% usage and then the system locks up. 

STEPS TO REPRODUCE
1. Load a game with an external monitor connected (a game that uses more memory will cause system to crash quicker).
2. Watch memory keep increasing until crash.

OBSERVED RESULT
System memory usage increases until system locks up and must be powered off. 'kwin_wayland --replace' is the quick (messy) fix or a reboot. The problem resumes as soon as the memory is cleared if system is used with an external monitor. I have done some testing withOUT an external display in a couple of games, eg Counter-Strike 2 and have observed memory usage is normal and drops off after exiting game.

EXPECTED RESULT
Memory should increase somewhat while gaming and then drop off afterwards. Not expected that kwin_wayland uses so much memory but rather it should be more the game.

ADDITIONAL INFO
I suspect watching full screen videos contributes also (with ext. monitor) but haven't tested yet.

SOFTWARE/OS VERSIONS/HARDWARE
Operating System: Garuda Linux 
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.12.0
Qt Version: 6.8.3
Kernel Version: 6.13.8-zen1-1-zen (64-bit)
Graphics Platform: Wayland

Processors: 16 × AMD Ryzen 7 5800H with Radeon Graphics
Memory: 15.0 GiB of RAM
Graphics Processor 1: AMD Radeon Graphics
Graphics Processor 2: NVIDIA GeForce RTX 3060 Laptop GPU
Manufacturer: ASUSTeK COMPUTER INC.
Product Name: ASUS TUF Gaming A15 FA506QM_TUF506QM
System Version: 1.0

Screens:
1. built in laptop
2. AOC CQ27G4 Monitor (DP)
3. SONY BRAVIA TV (HDMI)
Comment 6 qethanmoore+kde 2025-03-30 02:10:42 UTC
(In reply to Nick H from comment #5)
> Also getting this bug. I'll add full info if that's OK because I reproduce
> it slightly differently.
> 
> SUMMARY
> When playing games with external monitor connected, Kwin_Wayland
> increasingly uses all of the memory until system is at 100% usage and then
> the system locks up. 
> 
> STEPS TO REPRODUCE
> 1. Load a game with an external monitor connected (a game that uses more
> memory will cause system to crash quicker).
> 2. Watch memory keep increasing until crash.
> ...
>Screens:
>1. built in laptop
>2. AOC CQ27G4 Monitor (DP)
>3. SONY BRAVIA TV (HDMI)

This sounds more similar to https://bugs.kde.org/show_bug.cgi?id=496469 which I can't reproduce (at least not measurably) on my dual-monitor desktop, typical daily uptime of 15 hours
Comment 7 Nick H 2025-03-31 08:20:02 UTC
Ah yes. I saw that post just after filling out this report. At first I didn't think so but the more I read it seemed likely that it was that bug.