Bug 348156: Fix leaks by relying on cycle collector rather than calling UnbindFromTree on all nodes. r/sr=jst

This commit is contained in:
2007-11-30 09:57:03 -08:00
parent 0852ae3d8d
commit 7c4c5dce06
13 changed files with 103 additions and 30 deletions

View File

@@ -2857,6 +2857,22 @@ nsGenericElement::GetPrimaryFrameFor(nsIContent* aContent,
return presShell->GetPrimaryFrameFor(aContent);
}
void
nsGenericElement::DestroyContent()
{
nsIDocument *document = GetOwnerDoc();
if (document) {
document->BindingManager()->ChangeDocumentFor(this, document, nsnull);
document->ClearBoxObjectFor(this);
}
PRUint32 i, count = mAttrsAndChildren.ChildCount();
for (i = 0; i < count; ++i) {
// The child can remove itself from the parent in BindToTree.
mAttrsAndChildren.ChildAt(i)->DestroyContent();
}
}
//----------------------------------------------------------------------
// Generic DOMNode implementations
@@ -3340,6 +3356,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
PRUint32 i;
PRUint32 kids = tmp->mAttrsAndChildren.ChildCount();
for (i = kids; i > 0; i--) {
// We could probably do a non-deep unbind here when IsInDoc is false
// for better performance.
tmp->mAttrsAndChildren.ChildAt(i-1)->UnbindFromTree();
tmp->mAttrsAndChildren.RemoveChildAt(i-1);
}
@@ -3348,8 +3366,11 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
// Unlink any DOM slots of interest.
{
nsDOMSlots *slots = tmp->GetExistingDOMSlots();
if (slots)
if (slots) {
slots->mAttributeMap = nsnull;
if (tmp->IsNodeOfType(nsINode::eXUL))
NS_IF_RELEASE(slots->mControllers);
}
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END