If you’re a heavy tabs user, like most everyone in our office, you’ve probably seen Firefox go down in flames with Javascript errors.

Turns out, much of the problem was caused by too little available memory. Before 1.5.0.2, even those with a gigabyte of RAM ran into a hard-coded limit of 4MB for Last-Ditch Garbage Collection.

Firefox developers think the memory limitation may be the source for many of the crashes most frequently reported by the public.

Fixer-in-Chief Brendan Eich describes the scope of the trouble:

The problem with the 4MB threshold is actually two nasty bugs:
  1. You can hit it hard due to lots of JS objects, and you’re toast — no way around it. Even if you have 1GB of RAM and can well afford hundreds of megs on JS objects.
  2. You can hit it transiently, forcing a GC that does collect enough garbage to back off from the threshold by a decent interval. But hitting the threshold exposes more users to those bugs we’d rather find and fix by our own custom build stress-testing.

They fixed the bug by turning over responsibilty for locking-in the size of Javascript Garbage Collection (GC) to you. Otherwise, it will float as needed, just like… gulp… Microsoft’s much maligned Internet Explorer.

Developers were careful to maintain compatibility with earlier API versions, so Firefox can schedule its own GCs, and still run last-ditch GC whenever a specific byte limit is reached. This keeps those developers who embed Eich’s JavaScript in C engine, SpiderMonkey, happy and quiet.

The new floating GC system is also expected to be a boon for anyone developing large JavaScript-laden apps. You should appreciate it, too, if you habitually lots of Javascript-heavy web pages.

Is this the end of Firefox’s Javascript-crashing headaches? Developers sure hope so. At the least, they expect crashes to diminish.

Eich’s biggest complaint was the timing: “We should have done this for 1.5. The failure to raise or eliminate the threshold based on nominal heap size means greater memory pressure, sometimes putting the app on the edge of the cliff, where every allocation GCs. The app’s performance is miserable at that point, often bad enough that you have to kill it.”

Meanwhile, a key Microsoft advocate, Peter de Haas, is enjoying a smile at Mozilla’s expense, pointing to an article describing the major security and stability repairs in the update, and reminding us all that he’s “Just trying to keep score …;-)

Hey. In this match, everybody wins.

Email Battles Backgrounder: