Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
# Conflicts:
#	palemoon/config/version.txt
#	platform
  • Loading branch information
wolfbeast committed Oct 3, 2024
2 parents 94bd62a + 5b225ad commit 820e5c6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
6 changes: 6 additions & 0 deletions palemoon/app/profile/palemoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@ pref("javascript.options.showInConsole", true);
pref("general.warnOnAboutConfig", false);
#endif

// Enable unlinking of ghost windows so they can be garbage collected.
pref("browser.ghostbuster.enabled", true);
// Disable GC on memory pressure, avoid incessant recycling when websites
// misbehave. Should also avoid spurious GCs during ghostbusting.
pref("javascript.options.gc_on_memory_pressure", false);

// This is the pref to control the location bar, change this to true to
// force this - this makes the origin of popup windows more obvious to avoid
// spoofing. We would rather not do it by default because it affects UE for web
Expand Down
15 changes: 14 additions & 1 deletion palemoon/base/content/tabbrowser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2114,15 +2114,28 @@
}
// We're going to remove the tab and the browser now.
// Interrupt all tab activity to aid in cleaning up detached window objects.
// Using the "STOP_ALL" flag should halt all animations, fetches, network
// activity, etc. to come to a clean state for removal and unlinking (if enabled).
var browser = this.getBrowserForTab(aTab);
browser.webNavigation.stop(nsIWebNavigation.STOP_ALL);
// Clean up mTabFilters and mTabListeners now rather than in
// _beginRemoveTab, so that their size is always in sync with the
// number of tabs and browsers (the xbl destructor depends on this).
this.mTabFilters.splice(aTab._tPos, 1);
this.mTabListeners.splice(aTab._tPos, 1);
var browser = this.getBrowserForTab(aTab);
this._outerWindowIDBrowserMap.delete(browser.outerWindowID);
if (Services.prefs.getBoolPref("browser.ghostbuster.enabled", true)) {
Cu.unlinkGhostWindows();
#ifdef DEBUG
dump("Unlinking ghost windows has run on tab close.\n");
#endif
}
// Because of the way XBL works (fields just set JS
// properties on the element) and the code we have in place
// to preserve the JS objects for any elements that have
Expand Down
33 changes: 33 additions & 0 deletions palemoon/components/nsBrowserGlue.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const BOOKMARKS_BACKUP_INTERVAL = 86400 * 1000;
// Maximum number of backups to create. Old ones will be purged.
const BOOKMARKS_BACKUP_MAX_BACKUPS = 10;

// Use users' idle time to unlink ghost windows and clean up memory.
// Trigger this by default every 5 minutes.
const GHOSTBUSTER_INTERVAL = 5 * 60;

// Factory object
const BrowserGlueServiceFactory = {
_instance: null,
Expand All @@ -82,6 +86,10 @@ function BrowserGlue() {
"@mozilla.org/widget/idleservice;1",
"nsIIdleService");

XPCOMUtils.defineLazyServiceGetter(this, "_ghostBusterService",
"@mozilla.org/widget/idleservice;1",
"nsIIdleService");

XPCOMUtils.defineLazyGetter(this, "_distributionCustomizer", function() {
Cu.import("resource:///modules/distribution.js");
return new DistributionCustomizer();
Expand Down Expand Up @@ -111,6 +119,7 @@ BrowserGlue.prototype = {
_isPlacesShutdownObserver: false,
_isPlacesDatabaseLocked: false,
_migrationImportsDefaultBookmarks: false,
_isGhostBusterObserver: false,

_setPrefToSaveSession: function(aForce) {
if (!this._saveSession && !aForce) {
Expand Down Expand Up @@ -243,6 +252,15 @@ BrowserGlue.prototype = {
if (this._idleService.idleTime > BOOKMARKS_BACKUP_IDLE_TIME * 1000) {
this._backupBookmarks();
}
if (this._ghostBusterService.idleTime > GHOSTBUSTER_INTERVAL * 1000) {
if (Services.prefs.getBoolPref("browser.ghostbuster.enabled", true)) {
Cu.unlinkGhostWindows();
Cu.forceGC();
#ifdef DEBUG
dump("Unlinking ghost windows + GC has run on idle.\n");
#endif
}
}
break;
case "distribution-customization-complete":
Services.obs.removeObserver(this, "distribution-customization-complete");
Expand Down Expand Up @@ -625,6 +643,13 @@ BrowserGlue.prototype = {
DateTimePickerHelper.init();

this._trackSlowStartup();

// Initialize ghost window idle observer.
if (!this._isGhostBusterObserver) {
this._ghostBusterService.addIdleObserver(this, GHOSTBUSTER_INTERVAL);
// Prevent re-entry.
this._isGhostBusterObserver = true;
}
},

/**
Expand All @@ -641,6 +666,14 @@ BrowserGlue.prototype = {
FormValidationHandler.uninit();
AutoCompletePopup.uninit();
this._dispose();

// Shut down ghost window idle observer.
if (this._isGhostBusterObserver) {
this._ghostBusterService.removeIdleObserver(this, GHOSTBUSTER_INTERVAL);
this._isGhostBusterObserver = false;
}
// Do one final unlink to combat shutdown issues.
Cu.unlinkGhostWindows();
},

// All initial windows have opened.
Expand Down

0 comments on commit 820e5c6

Please sign in to comment.