Wednesday, December 27, 2006

Fast Firefox Fix Found

[Ed. Note: I know this looks like a pure geek entry and therefore something that you can skip, but if you browse with Firefox it's worth the time, trust me. And if you don't, like, what is your damage?] It's no secret that Firefox is a memory-leak hydra: every time the development team fixes one, two more spring up to take it's place. Build a large enough application and you're guaranteed to drop a few pointers here and there, and once you add in a Javascript engine, Chrome interfaces and a half-dozen or more extensions you might as well throw in the towel on your leak analyzer. This is the one area that Internet Explorer will always surpass Firefox. When you package most of your functionality as an integral part of the OS, your memory leaks are either found quickly or so deeply buried that you'd have to move Jimmy Hoffa to find them. On the other hand, Microsoft Visual Studio 2005 leaks like a sieve, but it's the most helpful development environment I've ever seen. Perhaps memory leaks are found due to usefulness the way security flaws stem from popularity. That theory would conveniently explain the balance of bugs in Microsoft's OS code. But I digress. There are some people (whose initials may be BMW) that will tell you that the best solution for this problem is to never install Firefox on a Microsoft OS. These are usually the same sort of people who still prefer vi to a text editor. Personally I'm not one to give up functionality for the sake of form, but what can a resource-constrained power-surfer do? Well, the traditional method of freeing up resources lost to a leak is to restart the application. Back in the old days (like, three months ago) this was a major pain, involving bookmarking or finishing any open tabs, logging in to sites again and losing any form data that you might have entered on any open pages. Of course, there were extensions to fix any of those problems, but often they were a cause of the very problems you were trying to fix. Thankfully, Firefox 2 fixed all that. I don't even want to know that you haven't updated yet, just go do it now. I'll wait. Anyway, Firefox 2 includes a crash recovery mode that can restore your entire session, usually without reloading the pages. Of course, this doesn't happen when you voluntarily close the browser, but you can see it in action when you install an extension. In fact, I suggest you check it out right now. Go install the Restarter extension from from the add-ons site. Once you've clicked the Install button (after the standard five-second penance), the Extension Manager will open to show the progress. Installing this tiny extension will probably take less time than the install delay. Once it's done, notice the Restart button? Click it. Go ahead, I'm patient. That served two purposes. First, you have now seen the session restore function at work. Until now, the only way to trigger that as a user was after installing an extension. However, the tiny little extension that you just installed added an item to your File menu. At the bottom, just above Exit, there is now a Restart Firefox option. This will do exactly what the Restart button just did for you, so you can try this whenever the browser seems to have gotten bloated and slow. This is far more convenient than a restart used to be, and it is guaranteed to free up any leaked memory, but it's still not always convenient. It's like rebooting the computer, almost guaranteed to fix the problem but sometimes like chasing a fly with a baseball bat. However, I found a potentially more useful tweak today in a post on Cybernet, which I found via Lifehacker's Best of April 2006. Here's what to do:
  1. Highlight the words config.trim_on_minimize and copy them to the clipboard.
  2. Open a new tab and type about:config in the address bar. This will display a page of Firefox's internal configuration values.
  3. Right-click anywhere on the page and select New -> Boolean from the context menu.
  4. Paste the copied text from above into the input box that appears and hit enter. Yes, you can type it if you'd prefer, I just found cut-and-paste more convenient.
  5. Select true as the value and click the OK button, then go to the File menu and click that new Restart Firefox option we just added.
So what did this accomplish? Well, now Firefox will unload most of itself from memory each time you minimize it. In my experiments, it went down to between 7M and 8M, from it's average of 40M to 50M (too many extensions loaded). Your results may (and probably will) vary, but from what I've been able to determine, at least some leaked memory is regained after you maximize the application. At the very least, you can free up a big chunk of system resources while you're doing something else without having to close the browser. This is a must for any serial tab abuser like myself, as well as anyone running on an ancient and/or overloaded system. I'm looking at you, Kare-Bear... just follow the instructions, you'll thank me later.

1 comment:

Anonymous said...

Stinking 2.0.1 won't work on my Mac...but I followed your other instructions. We shall see.