About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Home » Learning Curve

Keeping Up With Safari

It's a dirty job but you got to do it.

Buy It

Try It

Apple's most recent Safari release is a big setback. Suddenly the poor thing is leaking memory all over the place. To make matters worse its subordinate WebProcess leaks even worse. You have three options.

  1. Go over to Chrome. Not recommended. More about this below.
  2. Don't upgrade to 6.1 on Mountain Lion or lower. Keep saying 'no thanks' to Software Update.
  3. Assiduously watch the Safari leaks and regularly exit. This article concentrates on this option.

1. Go over to Chrome

Going over to Chrome because Safari suddenly leaks like a sieve is not to be recommended. Chrome can be insidious. Invasive. And you need work on the bundle before using the application and you need a thorough script to clean things up after every use.

You have to begin by searching throughout the bundle for anything with the name 'keystone' in it. You just remove it. Chrome should work well anyway, and odds are teh Googels will learn less about you.

After exiting Chrome you should apply the following script. (Yes all of that - it's a single command on a single line.)

rm -fr ~/Library/Application\ Support/Google/Chrome/Default/Archived\ History ~/Library/Application\ Support/Google/Chrome/Default/Cookies ~/Library/Application\ Support/Google/Chrome/Default/Current* ~/Library/Application\ Support/Google/Chrome/Default/databases/* ~/Library/Application\ Support/Google/Chrome/Default/Favicons ~/Library/Application\ Support/Google/Chrome/Default/Extensions/* ~/Library/Application\ Support/Google/Chrome/Default/History* ~/Library/Application\ Support/Google/Chrome/Default/Last* ~/Library/Application\ Support/Google/Chrome/Default/Local\ Storage/* ~/Library/Application\ Support/Google/Chrome/Default/Login* ~/Library/Application\ Support/Google/Chrome/Default/QuotaManager ~/Library/Application\ Support/Google/Chrome/Default/Top\ Sites ~/Library/Application\ Support/Google/Chrome/Default/User\ StyleSheets/* ~/Library/Application\ Support/Google/Chrome/Default/Visited\ Links ~/Library/Application\ Support/Google/Chrome/Default/Web\ Data ~/Library/Application\ Support/Google/Chrome/chrome_shutdown_ms.txt ~/Library/Application\ Support/Google/Chrome/Local\ State ~/Library/Application\ Support/Google/Chrome/Safe\ Browsing* ~/Library/Application\ Support/Google/Chrome/Service* ~/Library/Application\ Support/Google/Chrome/Temp/* ~/Library/Caches/Google

You could of course opt for the Firefox browser in Tor - that's also safer than Safari (or Chrome). The curators of the Tor project aren't working with the NSA.

2. Don't upgrade to 6.1 on Mountain Lion or lower

This entails saying 'no' to Software Update each time you're prompted to upgrade Safari. Note that if you've upgraded your OS to 10.9 Mavericks, you're screwed: the 'Safari 7' there is essentially the same product, with all the leaks you'll never learn to love.

You might also try to preempt disaster by keeping (or making) an install image of Safari 6.0. There are various ways to try this, but Apple are no longer making their download URLs available for public access. You slip up once and you're screwed.

3. Assiduously watch the Safari leaks and regularly exit

This instead of resigning yourself to rebooting every time your Mac gets that 'crippled' feeling.

You need to have ready access to the following command.

leaks Safari | grep "leaks for"; leaks WebProcess | grep "leaks for"

Preferably hide Safari when you're doing this (but don't exit). The search for leaks in WebProcess will likely kill your machine, Safari will go nuts, pages will blank out, etc. Spare yourself the ignominy. And just be patient. When the WebProcess leak count reaches into the hundreds, it might be time to exit.

You could also check the status of your 'swap' with a utility like this, but it costs.

The code for Swapwatch is based on code from Lightman which in turn uses an API created by Avie Tevanian himself, with the important distinction that Swapwatch polls your 'vm' directory and updates both on a timer and when applications launch or exit, or when Swapwatch itself is activated or deactivated.

The important fields for this concern are 'Pageouts' and 'Swap On Disk'. You start getting pageouts when the virtual memory manager starts running low on RAM, and you get something more than the starting 64 MB swap as well. Swapwatch is colour-coded to indicate green for OK, then yellow, then orange, then red as your situation gets gradually worse.

You could also drop to a command line (free but some vendors don't want you knowing) and simply list the contents of your 'vm' directory - anything more than a single swap file ('swapfile0') and you're in trouble.

$ ls -al /private/var/vm
total 8519680
drwxr-xr-x   4 root  wheel         136 Nov  7 01:29 .
drwxr-xr-x  28 root  wheel         952 Feb 22  2012 ..
-rw------T   1 root  wheel  4294967296 Nov  7 18:54 sleepimage
-rw-------   1 root  wheel    67108864 Nov  7 01:29 swapfile0

[Note that 'sleepimage' has nothing to do with this matter. And you should never try removing swap files or any files from that directory. Ed.]

Exiting and relaunching Safari should be enough. You can keep your cookies and everything. Exiting Safari should also kill the bigger bastard: WebProcess. Fire up Activity Monitor and search for 'Safari Web Content'. That's WebProcess. Exit Safari and 'Safari Web Content' (WebProcess) should disappear too.

Then start Safari again and all should be back to normal.

[Note that Safari is currently so pathetic that it loses memory on launch alone, before even visiting a site or opening a file. Ed.]

Process 14086: 6 leaks for 1152 total leaked bytes.
Process 14087: 0 leaks for 0 total leaked bytes.

And if things go south, then they go south. Take the time and hard reboot the sucker. And hope for the best, namely that quality assurance at Apple improves by the next release.

See Also
The Technological: Safari Beware
Developers Workshop: Safari Leaking Good!

About | ACP | Buy | Forum | Industry Watch | Learning Curve | Search | Twitter | Xnews
Copyright © Rixstep. All rights reserved.