Leak Monitor Extension

Summary

This Firefox extension detects one very specific type of memory leak in chrome JavaScript and in Web pages. (Not in JavaScript components, though.) It detects when JavaScript objects in the chrome or Web page are still held by native code after the window is closed. It notifies the user after the first full garbage collection (i.e., cycle collection) after the window has been closed, so that the user is most likely to be able to correlate the notification with the action that caused it.

Some of these leaks are things that are clearly bugs in the extension (such as registering observers with the observer service forever) and some are things that arguably shouldn't leak (at varying argument strengths). It should not be possible to cause leaks using only APIs that are exposed to Web pages, since Web pages should not be able to cause leaks.

In Firefox 3, 3.5, and 3.6, there are a number of bugs that cause objects to be retained for a small number of cycles of garbage collection but then get collected. In these cases, Leak Monitor will display multiple alerts: a leak alert after the first cycle collection, and then one or more reclaimed leak alerts when the objects are actually collected. While these bugs are not actually leaks, they are likely to be caused by underlying bugs that are capable of causing leaks on slightly different testcases. They should be filed in Bugzilla, but very few of them are. They also make Leak Monitor very difficult to use in these versions of Firefox because of all the noise.

In Firefox 2 (and in trunk nightlies starting with 2006-05-26, and 1.8 branch nightlies (for 1.8.1) starting with 2006-06-15), there were no known bugs through which Web pages could cause leaks observed by leak monitor, since bug 241518, bug 206520, bug 323534, and bug 324871 were all fixed. These bugs were present in Firefox 1.5 and earlier, in which Web pages could cause this type of leak. However, in many cases, Web pages and extension authors could work around these leaks, for example, by calling removeEventListener to match addEventListener for any functions added as event listeners.

Get the extension

Passing test cases

These are some things I test when testing the extension.

Feedback I've heard

Further Reading


Valid HTML 4.0!

(Back to Mozilla Stuff, David Baron)

LDB, dbaron@dbaron.org, 2006-05-01