function minimizeMemoryUsage3x(fAfter)
{
  let i = 0;

  function runSoon(f)
  {
    let tm = Cc["@mozilla.org/thread-manager;1"]
              .getService(Ci.nsIThreadManager);

    tm.mainThread.dispatch({ run: f }, Ci.nsIThread.DISPATCH_NORMAL);
  }

  function sendHeapMinNotificationsInner()
  {
    let os = Cc["@mozilla.org/observer-service;1"]
             .getService(Ci.nsIObserverService);
    os.notifyObservers(null, "memory-pressure", "heap-minimize");

    if (++i < 3) {
      runSoon(sendHeapMinNotificationsInner);
    } else {
      os.notifyObservers(null, "after-minimize-memory-usage", "about:memory");
      runSoon(fAfter);
    }
  }

  sendHeapMinNotificationsInner();
}
// Ideally a single notification would be enough.
Ideally a single notification would be enough.
Ideally a single notification would be enough .
function minimizeMemoryUsage3x(fAfter)
{
  let i = 0;
  function runSoon(f)
  {
    let tm = Cc["@mozilla.org/thread-manager;1"]
              .getService(Ci.nsIThreadManager);
    tm.mainThread.dispatch({ run: f }, Ci.nsIThread.DISPATCH_NORMAL);
  }
  function sendHeapMinNotificationsInner()
  {
    let os = Cc["@mozilla.org/observer-service;1"]
             .getService(Ci.nsIObserverService);
    os.notifyObservers(null, "memory-pressure", "heap-minimize");
    if (++i < 3) {
      runSoon(sendHeapMinNotificationsInner);
    } else {
      os.notifyObservers(null, "after-minimize-memory-usage", "about:memory");
      runSoon(fAfter);
    }
  }
  sendHeapMinNotificationsInner();
}
function minimizeMemoryUsage3x ( fAfter ) { let i = 0 ; function runSoon ( f ) { let tm = Cc [ "@mozilla.org/thread-manager;1" ] . getService ( Ci . nsIThreadManager ) ; tm . mainThread . dispatch ( { run : f } , Ci . nsIThread . DISPATCH_NORMAL ) ; } function sendHeapMinNotificationsInner ( ) { let os = Cc [ "@mozilla.org/observer-service;1" ] . getService ( Ci . nsIObserverService ) ; os . notifyObservers ( null , "memory-pressure" , "heap-minimize" ) ; if ( ++ i < 3 ) { runSoon ( sendHeapMinNotificationsInner ) ; } else { os . notifyObservers ( null , "after-minimize-memory-usage" , "about:memory" ) ; runSoon ( fAfter ) ; } } sendHeapMinNotificationsInner ( ) ; }
Ideally a single notification would be enough.
Ideally a single notification would be enough .