diff --git a/toolkit/components/aboutmemory/content/aboutMemory.js b/toolkit/components/aboutmemory/content/aboutMemory.js index f4f042882b8d..1efffff95988 100644 --- a/toolkit/components/aboutmemory/content/aboutMemory.js +++ b/toolkit/components/aboutmemory/content/aboutMemory.js @@ -40,6 +40,7 @@ const Cc = Components.classes; const Ci = Components.interfaces; +const Cu = Components.utils; // Must use .href here instead of .search because "about:memory" is a // non-standard URL. @@ -73,6 +74,49 @@ function $(n) return document.getElementById(n); } +function doGlobalGC() +{ + Cu.forceGC(); + update(); +} + +function doGlobalGCandCC() +{ + window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils) + .garbageCollect(); + update(); +} + +// For maximum effect, this returns to the event loop between each +// notification. See bug 610166 comment 12 for an explanation. +// Ideally a single notification would be enough. +function sendHeapMinNotifications() +{ + function runSoon(f) + { + var tm = Cc["@mozilla.org/thread-manager;1"] + .getService(Ci.nsIThreadManager); + + tm.mainThread.dispatch({ run: f }, Ci.nsIThread.DISPATCH_NORMAL); + } + + function sendHeapMinNotificationsInner() + { + var os = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + os.notifyObservers(null, "memory-pressure", "heap-minimize"); + + if (++j < 3) + runSoon(sendHeapMinNotificationsInner); + else + runSoon(update); + } + + var j = 0; + sendHeapMinNotificationsInner(); +} + /** * Top-level function that does the work of generating the page. */ @@ -143,6 +187,23 @@ function update() } } + // Memory-related actions. + const GCDesc = "Do a global garbage collection."; + // XXX: once bug 625302 is fixed, should change this button to just do a CC. + const CCDesc = "Do a global garbage collection followed by a cycle " + + "collection. (It currently is not possible to do a cycle " + + "collection on its own, see bug 625302.)"; + const MPDesc = "Send three \"heap-minimize\" notifications in a row. Each " + + "notification triggers a global garbage collection followed " + + "by a cycle collection, and causes the process to reduce " + + "memory usage in other ways, e.g. by flushing various caches."; + + text += "