The Firefox preferences system is quite amazing, but it has a tendency to cache preference settings in memory, and only seems to write to disk (the prefs.js file in the current profile folder) when Firefox exits. This means that if Firefox should crash for some reason after changing preferences, the changes would be lost.

I looked and I looked for some sort of XPCOM call that would flush the preferences cache to disk, but couldn’t find anything. The best I could find was the savePrefFile call on nsIPrefService. Unfortunately, this procedure takes a file argument, so it isn’t really a flush.

Fortunately, I did some digging around in the code that implements the preferences service. It turns out that SavePrefFile calls SavePrefFileInternal, which includes a special check for a null parameter. If the parameter is null, then it writes to the mCurrentFile member, which I assume is equivalent to doing the flush.

In summary, while Firefox provides no explicit method to flush the preferences cache to disk, calling the savePrefFile method of nsIPrefService with a null parameter should do the trick.