Handle growing SystemUIServer memory usage
Sep 20, '10 07:30:00AM
Contributed by: name99
iStat is a great program for keeping track of your system by displaying menulings showing CPU usage, memory usage etc. In Mac OS X menulings (also called menu extras) are managed by a program called SystemUIServer.
iStat appears to have a memory leak where over time, the REAL memory used by SystemUIServer grows basically without bound. Memory usage that should be around 40MB balloons to 300MB then to 1.3GB over a few weeks of never rebooting. This would be bad enough if it was the virtual address space that was being used up this way, but this is real memory, causing real memory pressure and real swapping.
Obviously the ideal would be for Bjango to get on the case and fix this bug. Since they appear unwilling to do so, I have come up with a workaround.
The following facts are relevant to the workaround.
- A separate copy of SystemUIServer runs on behalf of each user, owned by that user, when the user has a GUI login. This is very convenient because it means we can kill this program without requiring passwords and suchlike.
- SystemUIServer appears to have been very nicely cordoned off by Apple from the rest of the system so that you can kill it at any time and nothing bad happens. The menulings all disappear, then launch restarts SystemUIServer, and the menulings all reappear (in a much smaller memory environment).
- So the simple one-off solution to the problem is to type in Terminal:
killall SystemUIServer. And this works, but only once --- you will need to do it again in a week or so.
- The possibility I chose is to have launchd execute this command once a day, at a time when I'm probably not using the machine, namely 4:00am. (If your machine is asleep at that time, launchd in Snow Leopard performs the task when the machine is wakes up, and this works out OK --- we see just one more flash in the UI as the menulings are killed then restart, to accompany the various other flashes in the UI that occur when a wake occurs.
To make this all happen is not too hard. You need to create a launchd script, I called mine my.SystemUIServer_cleaner.plist, and populate it as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.SystemUIServer_cleaner</string>
<key>ProgramArguments</key>
<array>
<string>killall</string>
<string>SystemUIServer</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>4</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Put this in /Library/LaunchAgents, and make sure it is owned by root:
cd /Library/LaunchAgents
sudo chown root:wheel my.SystemUIServer_cleaner.plist
This file will only be noticed by launchd and kick in automatically when you logout then login again. If you don't want to do that, but do want it to start working right away, you can manually tell launchd about it using:
sudo launchctl load /Library/LaunchAgents/my.SystemUIServer_cleaner.plist
[crarko adds: I haven't tested this one. This would be applicable to managing runaway SystemUIServer memory in general if you observe it, and not just for iStat. It's also a good example of a simple launchd script.]
Comments (18)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20100918163629993