Closed
Bug 480773
Opened 16 years ago
Closed 16 years ago
Preference observers stop working after a few observations
Categories
(Core :: Preferences: Backend, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: jason.barnabe, Unassigned)
Details
Tested in Firefox 3.0.6 and 3.1b2 on Ubuntu.
The attached test extension adds a pref observer to browser windows that alerts whenever extensions.preftest.test changes.
1. Install the extension and close Firefox
2. Open one Firefox window
3. Go to about:config and toggle extensions.preftest.test a few times. You can see that it alerts the name of the pref and the value.
4. Open a second Firefox window
5. In the first window, toggle extensions.preftest.test some more. It should be alerting twice (once for each window).
6. Keep toggling
Expected results:
You keep getting two alerts every time you toggle the pref.
Actual Results:
As you keep toggling, eventually one or both windows stop alerting. This usually happens around the 4th toggle with both windows open for me. This is blocking me from adding a new feature to my extension, so requesting blocking.
The relevant code in the extension is simply:
var prefTestOverlay = {
init: function() {
Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.preftest.").QueryInterface(Components.interfaces.nsIPrefBranch2).addObserver("", prefTestOverlay, false);
},
observe: function(subject, topic, data) {
//Components.utils.reportError(data + " " + subject.QueryInterface(Components.interfaces.nsIPrefBranch2).getBoolPref(data));
alert(data + " " + subject.QueryInterface(Components.interfaces.nsIPrefBranch2).getBoolPref(data));
}
}
addEventListener("load", prefTestOverlay.init, false);
Flags: blocking1.9.1?
Comment 1•16 years ago
|
||
Not gonna block this release since it's not a regression.
Flags: blocking1.9.2?
Flags: blocking1.9.1?
Flags: blocking1.9.1-
Comment 2•16 years ago
|
||
The preference branch object that you added your observer to is being GCed, since you're not keeping a reference to it. You need to keep a reference to the preference branch to keep it alive. This should perhaps be better documented on the interface...
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → INVALID
Comment 3•16 years ago
|
||
Alternatively, you could add your observer on the root branch, which is kept alive by the preferences service (you can QI the preferences service to nsIPrefBranch[2], it forwards those calls to the root branch).
Updated•16 years ago
|
Flags: blocking1.9.2?
You need to log in
before you can comment on or make changes to this bug.
Description
•