Closed Bug 419655 Opened 17 years ago Closed 17 years ago

Refreshing a page leaks an nsGlobalWindow until shutdown

Categories

(Core :: DOM: Core & HTML, defect, P1)

x86
macOS
defect

Tracking

()

VERIFIED FIXED
mozilla1.9beta4

People

(Reporter: bent.mozilla, Assigned: bent.mozilla)

Details

(Keywords: memory-leak)

Attachments

(2 files)

There are at least 3 different causes: 1) nsSecureBrowserUIImpl is involved in an ownership cycle but is not cycle collected. 2) nsFocusController is improperly traversed. 3) There's something else that I haven't found yet...
Flags: blocking1.9?
Target Milestone: --- → mozilla1.9beta4
Assignee: nobody → bent.mozilla
Keywords: mlk
Moving bugs that aren't beta 4 blockers to target final release.
Target Milestone: mozilla1.9beta4 → mozilla1.9
Attached patch Patch, v1Splinter Review
So #3 was the navigator object's prototype keeping a reference to the window in which it was created. This patch fixes issues 1-3 and allows us to reclaim the windows destroyed during a refresh.
Attachment #306147 - Flags: review?(peterv)
Flags: tracking1.9? → blocking1.9?
Comment on attachment 306147 [details] [diff] [review] Patch, v1 >+ cb.NoteXPCOMChild(tmp->mOwnerContent->GetOwnerDoc()->GetWindow()); This seems rather unusual. Does it really hold a reference directly to that window rather than to one of the intermediate objects? If so, you should probably have a comment explaining how.
(In reply to comment #3) > Does it really hold a reference Yeah, mDocShell holds an nsIScriptGlobalObject which is an nsGlobalWindow... Sadly nsDocShell is not cycle-collected so the previous Traverse code was basically a no-op, even though the docshell directly owns the window. This way we at least get the cycle collector happy by accounting for its last remaining unknown reference.
Comment on attachment 306147 [details] [diff] [review] Patch, v1 >+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFrameLoader) >+ cb.NoteXPCOMChild(tmp->mOwnerContent->GetOwnerDoc()->GetWindow()); This won't work. You're recording one edge from nsFrameLoader to mOwnerContent->GetOwnerDoc()->GetWindow(), but you're ignoring other edges to mDocShell. Imagine that something else holds a strong reference to that docshell. So two objects hold the docshell and the docshell holds the window. The window has a reference count of 1 and you just recorded 1 edge to it here. So we'll unlink the window, even though the window might be held alive by something not in a cycle.
Attachment #306147 - Flags: review?(peterv) → review-
Comment on attachment 306147 [details] [diff] [review] Patch, v1 >diff -NprU8 mozilla.faca22b69aa0/security/manager/boot/src/nsSecureBrowserUIImpl.cpp mozilla/security/manager/boot/src/nsSecureBrowserUIImpl.cpp > nsSecureBrowserUIImpl::Init(nsIDOMWindow *window) > { >+ nsCOMPtr<nsIDOMWindow> strongWindow = do_QueryReferent(mWindow); ifdef PR_LOGGING. >+ mWindow = do_GetWeakReference(window); >+ NS_ENSURE_TRUE(mWindow, NS_ERROR_FAILURE); Maybe do_GetWeakReference(window, &rv) and NS_ENSURE_SUCCESS. >+ strongWindow = window; No need for this, just use window instead below. >@@ -611,17 +618,18 @@ nsSecureBrowserUIImpl::OnStateChange(nsI >- const PRBool isToplevelProgress = (windowForProgress.get() == mWindow.get()); >+ nsCOMPtr<nsIDOMWindow> strongWindow = do_QueryReferent(mWindow); >+ const PRBool isToplevelProgress = (windowForProgress == strongWindow); Should this check for non-null strongWindow? r=peterv, except on the nsFrameLoader changes.
Attachment #306147 - Flags: review- → review+
Attached patch Patch, v2Splinter Review
Fixed peterv's comments... Turns out that the window dies properly even without traversing the docshell held by the frame loader (although I don't really understand why) as long as these other two references get caught. I'm also ASSERTing that the window doesn't go away as I think it really should never happen as the window owns the secure impl.
Attachment #306375 - Flags: superreview?(jst)
Attachment #306375 - Flags: review+
Comment on attachment 306375 [details] [diff] [review] Patch, v2 sr=jst I'd do a s/strongWindow/window/g on the secure browser UI changes, but I can deal either way.
Attachment #306375 - Flags: superreview?(jst) → superreview+
Plussing, we should get this in for beta4, even!
Flags: blocking1.9? → blocking1.9+
Priority: -- → P1
Target Milestone: mozilla1.9 → mozilla1.9beta4
Attachment #306375 - Flags: approval1.9b4?
Comment on attachment 306375 [details] [diff] [review] Patch, v2 Let's get this in tonight for nightly baking
Attachment #306375 - Flags: approval1.9b4? → approval1.9b4+
Fixed for beta 4.
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Flags: in-testsuite?
Removing dependency on bug 372107 because the leak was fixed without it.
No longer depends on: 372107
verified fixed using Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9b5pre) Gecko/2008032615 Firefox/3.0b5pre ID:2008032615
Status: RESOLVED → VERIFIED
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: