Bug 317961

Summary: GTK apps in system tray leak X resources
Product: [Plasma] plasma4 Reporter: Eevee <eevee.kdebugs>
Component: widget-systemtrayAssignee: Plasma Bugs List <plasma-bugs>
Severity: minor CC: rdieter
Priority: NOR    
Version: 4.10.2   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Eevee 2013-04-07 01:40:53 UTC
For many months now I've been experiencing significant graphical slowdowns in KDE, with the only quantifiable symptom being a ludicrously high "misc" count in xrestop for plasma-desktop—I start to get noticeable lag around 40k, but have caught it as high as 150k+.  Killing and restarting plasma-desktop alleviates the problem, but only temporarily.

At last I've found the culprit.  If a GTK+ app is in the system tray, and it changes its icon, a single X "picture" leaks.  I suspect a great many people are experiencing this, but few actually notice it.  I just happen to be running WhatPulse, a GTK+ keycounter that briefly changes its icon (to show a dot registering a counted key) /every single time/ I press a key or click a mouse button.

An easier demonstration is Pidgin:
1. Open a terminal and leave `xrestop` running.
2. Open Pidgin and sign into some account.  Enable Pidgin's system tray icon if necessary.  (Tools > Preferences > Interface > Show system tray icon: Always)
3. Find plasma-desktop in xrestop and watch its "misc" column; wait until the misc count stabilizes.
4. Change Pidgin's status to Away.  plasma-desktop's "misc" resource count increases by 1.
5. Change Pidgin's status back to Available.  plasma-desktop's "misc" resource count again increases by 1.

The "misc" count will never reclaim the old icon.  Perform this dance tens of thousands of times, and KDE will start to noticeably lag.  Disabling Pidgin's system tray icon, hiding Pidgin from the system tray, or removing the system tray from your panel altogether will avoid the leak.  Nothing else seems to help, and the only way to drop the count is to restart plasma-desktop.

As far as I can tell, this only happens with GTK+ apps.  Muting and unmuting the volume to change the KMix icon, for example, doesn't change the "misc" count at all.  But both Pidgin and WhatPulse reproduce the leak every time.

A similar issue occurs with `uim-toolbar-gtk-systray`: whenever I switch workspaces with the icon visible, one X picture leaks.  I'm not entirely sure why this is, but I'd guess that uim is resetting its icon during a workspace change for some reason.  Again, if I hide the uim icon (which somewhat defeats the purpose of having it), nothing leaks.

Arch Linux x86_64, KDE 4.10.2 (but observed on many versions going back possibly a year or more).  GTX 460 with the latest nvidia blob driver.  

Reproducible: Always
Comment 1 Jekyll Wu 2013-04-07 02:19:16 UTC

*** This bug has been marked as a duplicate of bug 314919 ***