Open Bug 647998 Opened 13 years ago Updated 2 years ago

Should assert when a not-yet-fired nsITimer is GCed

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

People

(Reporter: jruderman, Unassigned)

Details

See bug 640629 for the latest round of screw-ups.

I understand that we can't change the GC behavior of nsITimer right now. Can we at least make it assert-fail, so it doesn't just make pieces of the browser fail quietly and mysteriously?  At least for one-shot timers?
I've never understood why we can't make timers root themselves while they are pending (and we're not shutting down)... can we just do that, and perhaps deal with the little bit of leak fallout that might happen?
That seems fine offhand to me.  Brendan, any reason not to do that?
Hrm, bug 387341 seems related.
I agree that the only sane model for timers is that they are rooted as long as they can fire in the future. It's terribly wrong for whether a timer fires or not to depend on the timing of GC.

We would have to audit users of repeating timers, at least, to make sure something cancels them. And obviously JS setTimeout/setInterval would have to cancel automatically when a window needs to go away.
That last part works already: nsGlobalWindow::SetDocshell calls FreeInnerObjects on all the inners when aDocShell is null, and FreeInnerObjects calls ClearAllTimeouts, which cancels all the timer.  This covers the "window closing" case.  FreeInnerObjects is also called from nsGlobalWindow::SetNewDocument, which is what happens in the "navigating away" case.
Component: General → XPCOM
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.