From 493c3add8a492902a3f10bf2e706417d1897256e Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Thu, 1 Feb 2024 05:44:22 +0000 Subject: [PATCH] Fix a memory leak in file renaming preferences pane (#3654) --- chrome/content/zotero/preferences/preferences.js | 7 +++++++ .../zotero/preferences/preferences_file_renaming.js | 11 ++++++++++- .../preferences/preferences_file_renaming.xhtml | 6 +++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js index b9a9200425..9c9d56e785 100644 --- a/chrome/content/zotero/preferences/preferences.js +++ b/chrome/content/zotero/preferences/preferences.js @@ -102,6 +102,13 @@ var Zotero_Preferences = { Zotero.Prefs.unregisterObserver(symbol); } this._observerSymbols.clear(); + + for (let [_key, pane] of this.panes) { + for (let child of pane.container.children) { + let event = new Event('unload'); + child.dispatchEvent(event); + } + } }, waitForFirstPaneLoad: async function () { diff --git a/chrome/content/zotero/preferences/preferences_file_renaming.js b/chrome/content/zotero/preferences/preferences_file_renaming.js index eaf71d29bf..0a1f31830c 100644 --- a/chrome/content/zotero/preferences/preferences_file_renaming.js +++ b/chrome/content/zotero/preferences/preferences_file_renaming.js @@ -31,7 +31,16 @@ Zotero_Preferences.FileRenaming = { this.inputRef = document.getElementById('file-renaming-format-template'); this.updatePreview(); this.inputRef.addEventListener('input', this.updatePreview.bind(this)); - Zotero.getActiveZoteroPane()?.itemsView.onSelect.addListener(this.updatePreview.bind(this)); + + this._itemsView = Zotero.getActiveZoteroPane()?.itemsView; + this._updatePreview = this.updatePreview.bind(this); + if (this._itemsView) { + this._itemsView.onSelect.addListener(this._updatePreview); + } + }, + + uninit: function () { + this._itemsView.onSelect.removeListener(this._updatePreview); }, getActiveTopLevelItem() { diff --git a/chrome/content/zotero/preferences/preferences_file_renaming.xhtml b/chrome/content/zotero/preferences/preferences_file_renaming.xhtml index 2ed192c4de..c31d2c044e 100644 --- a/chrome/content/zotero/preferences/preferences_file_renaming.xhtml +++ b/chrome/content/zotero/preferences/preferences_file_renaming.xhtml @@ -22,7 +22,11 @@ ***** END LICENSE BLOCK ***** --> - +