Closed
Bug 624202
Opened 14 years ago
Closed 14 years ago
Make sure to remove subscribers
Categories
(Firefox Graveyard :: Panorama, defect, P1)
Firefox Graveyard
Panorama
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 4.0b12
People
(Reporter: mitcho, Assigned: ehsan.akhgari)
References
Details
(Keywords: memory-leak, Whiteboard: [qa-][cleanup][potential leak])
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
iangilman
:
review+
Dolske
:
approval2.0+
|
Details | Diff | Splinter Review |
We have, by my count, three places where we're adding subscribers and they don't remove themselves after being fired:
groupitems.js:
681 child.addSubscriber(self, "close", function() {
682 self.remove(child);
683 });
900 item.addSubscriber(this, "close", function() {
901 self.remove(item);
902 });
ui.js:
369 this._activeTab.addSubscriber(this, "close", function() {
370 self._activeTab = null;
371 });
In addition, I believe I've seen (on my leak hunt) other subscribers which, if they don't get fired, don't actually get removed... but that'll have to be a more systematic search and can be another bug. For starters, let's patch these three potential leaks.
Reporter | ||
Updated•14 years ago
|
Severity: normal → major
Priority: -- → P1
Whiteboard: [qa-][cleanup]
Assignee | ||
Comment 1•14 years ago
|
||
The first two shouldn't cause leaks, should they?
Reporter | ||
Comment 2•14 years ago
|
||
(In reply to comment #1)
> The first two shouldn't cause leaks, should they?
I'm not entirely sure. Ehsan, can we assign this to you?
Assignee | ||
Comment 3•14 years ago
|
||
(In reply to comment #2)
> (In reply to comment #1)
> > The first two shouldn't cause leaks, should they?
>
> I'm not entirely sure. Ehsan, can we assign this to you?
Please do.
Reporter | ||
Updated•14 years ago
|
Assignee: nobody → ehsan
Whiteboard: [qa-][cleanup] → [qa-][cleanup][potential leak]
Assignee | ||
Comment 4•14 years ago
|
||
Attachment #508167 -
Flags: review?(ian)
Assignee | ||
Updated•14 years ago
|
Attachment #508167 -
Attachment is patch: true
Attachment #508167 -
Attachment mime type: application/octet-stream → text/plain
Comment 5•14 years ago
|
||
(In reply to comment #1)
> The first two shouldn't cause leaks, should they?
Agreed; remove() takes care of it.
Comment 6•14 years ago
|
||
Comment on attachment 508167 [details] [diff] [review]
Patch (v1)
I believe it should be:
closedTabItem.removeSubscriber(self, "close");
… just in case.
R+ with that change
Attachment #508167 -
Flags: review?(ian) → review+
Assignee | ||
Comment 7•14 years ago
|
||
(In reply to comment #6)
> Comment on attachment 508167 [details] [diff] [review]
> Patch (v1)
>
> I believe it should be:
>
> closedTabItem.removeSubscriber(self, "close");
>
> … just in case.
>
> R+ with that change
Hmm, why is that? closedTabItem could be different to self._activeTab, right?
Comment 8•14 years ago
|
||
(In reply to comment #7)
> > I believe it should be:
> >
> > closedTabItem.removeSubscriber(self, "close");
> >
> > … just in case.
> >
> > R+ with that change
>
> Hmm, why is that? closedTabItem could be different to self._activeTab, right?
Correct. closedTabItem will always be the object sending the message, and that's who you want to be unsubscribing from.
Assignee | ||
Comment 9•14 years ago
|
||
(In reply to comment #8)
> (In reply to comment #7)
> > > I believe it should be:
> > >
> > > closedTabItem.removeSubscriber(self, "close");
> > >
> > > … just in case.
> > >
> > > R+ with that change
> >
> > Hmm, why is that? closedTabItem could be different to self._activeTab, right?
>
> Correct. closedTabItem will always be the object sending the message, and
> that's who you want to be unsubscribing from.
If that's the case, why do we need to explicitly check it on the next line? :-)
Comment 10•14 years ago
|
||
(In reply to comment #9)
> > > Hmm, why is that? closedTabItem could be different to self._activeTab, right?
> >
> > Correct. closedTabItem will always be the object sending the message, and
> > that's who you want to be unsubscribing from.
>
> If that's the case, why do we need to explicitly check it on the next line?
> :-)
Because closedTabItem could be different to self._activeTab. I feel like we're going around in circles.
The idea is that there's only one _activeTab, and every time you change it, you unsubscribe from the old one and subscribe to the new one, so I suppose theoretically we don't need these checks at all. We have them because I feel it's good defensive programming. So, the scenario that we're defending against is that we've changed _activeTab but didn't unsubscribe from the old one before its "close" fires. In this case, you want to make sure to unsubscribe closedTabItem (because it's the object sending the event... unsubscribing the new _activeTab would be wrong), and you only want to set _activeTab to null if the object getting closed is in fact _activeTab.
Even if we decide that this scenario could never occur, it's still more correct to unsubscribe closedTabItem, because it's the actual thing sending the event, and the only reason we would be getting the event is because we had subscribed to it.
Does that make sense? If not, let's discuss in IRC.
Assignee | ||
Comment 11•14 years ago
|
||
OK, reading the description in comment 10, your comment makes perfect sense. Sorry, I didn't fully understand what's happening here.
So, here's another question: would it make sense for us to take another patch, namely one which replaces the |self._activeTab = null;| with a |self.setActiveTab(null);| call? This way, removeSubscriber is taken care of, and MakeDeactive also gets called. Does that make more sense?
Comment 12•14 years ago
|
||
(In reply to comment #11)
> So, here's another question: would it make sense for us to take another patch,
> namely one which replaces the |self._activeTab = null;| with a
> |self.setActiveTab(null);| call? This way, removeSubscriber is taken care of,
> and MakeDeactive also gets called. Does that make more sense?
That would certainly work, too. makeDeactive isn't really necessary in this case, as the tab is closing, but it doesn't hurt. It's probably better design to call self.setActiveTab(null) so we're consolidating code paths.
Assignee | ||
Comment 13•14 years ago
|
||
OK then!
Attachment #508167 -
Attachment is obsolete: true
Attachment #509638 -
Flags: review?(ian)
Comment 14•14 years ago
|
||
Comment on attachment 509638 [details] [diff] [review]
Patch (v2)
Voila
Attachment #509638 -
Flags: review?(ian) → review+
Assignee | ||
Updated•14 years ago
|
Attachment #509638 -
Flags: approval2.0?
Updated•14 years ago
|
Attachment #509638 -
Flags: approval2.0? → approval2.0+
Assignee | ||
Updated•14 years ago
|
Whiteboard: [qa-][cleanup][potential leak] → [qa-][cleanup][potential leak][needs landing]
Assignee | ||
Comment 15•14 years ago
|
||
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Whiteboard: [qa-][cleanup][potential leak][needs landing] → [qa-][cleanup][potential leak]
Target Milestone: --- → Firefox 4.0b12
Updated•9 years ago
|
Product: Firefox → Firefox Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•