Re: Leaks in nsSessionStore.js?
"Nickolay Ponomarev" <[email protected]> Sun, 18 Nov 2007 17:54:32 +0300
| Newsgroups | gmane.comp.mozilla.performance |
|---|---|
| Message-ID | <[email protected]> |
On Nov 18, 2007 7:18 AM, Michael Vincent van Rantwijk, MultiZilla <[email protected]> wrote: > Okay, so weak references should only be used in components. Should not be used outside components. And I was only thinking about the observer service case. For that case there's not much value in using the weak references even in components, as far as I can see. Perhaps the "service is an observer" case (as for the session store component) and the "component that wants to observe notifications while it's held to by something else, but doesn't have an explicit destroy() method" case. > > Otherwise since there is a period of time when the window is closed, > > but the GC hasn't happened, your observer may run in a closed window, > > which usually leads to scary-sounding assertions and wrong behavior > > (JS errors at least). > > Dialogs leaked like crazy in older builds, because the button observers > where not removed, but I guess that this so called 'cycle collector' (or > whatever the name is) takes care of it now, but only for strong observers? > My understanding is that it doesn't, since this kind of leak is not due to cycles: the observer simply cannot be destroyed while it's held by the observer service (for strong references). My point was that even if the observer service doesn't hold a reference to your observer (i.e. you registered it via a weak reference) and even though such observer will be collected eventually, the collection does not happen exactly at the moment when the observer's window is destroyed. This means there's a chance that the observer will be notified after its window is gone, which is bad. Nickolay