Open Bug 1167746 Opened 11 years ago Updated 4 years ago

Make CSSStyleSheet::mOwningNode a smart pointer

Categories

(Core :: CSS Parsing and Computation, defect)

defect

Tracking

()

People

(Reporter: nika, Unassigned)

Details

Attachments

(1 file)

I'm trying to figure out why this patch is causing a leak. This is the failing try link (The other patches are trivial and only add comments and annotations): https://treeherder.mozilla.org/#/jobs?repo=try&revision=337c86580afd As far as I can tell, the only place where mOwningNode is set is nsStyleLinkElement::SetStyleSheet(). AFAICT nsStyleLinkElement participates in cycle collection, and both traverses and unlinks its mStyleSheet element, which makes me confused as to why the cycle isn't being collected.
Attachment #8609607 - Flags: feedback?(continuation)
Those are all "leaked until shutdown". So the windows are eventually cleaned up, they just aren't cleaned up quickly enough. I haven't spent a huge amount of time investigating those kinds of leaks, so I don't have a lot of intuition as to what might be causing it. One example is some kind of global structure that gets explicitly torn down in shutdown. Another possible problem would be CCed stuff holding onto non-CCed stuff holding onto CCed stuff: this would take a few rounds of CCing to actually tear down, which might not be fast enough. Maybe try needinfo-ing dbaron or bz and see if they have any ideas? They are more familiar with the expectations of ownership here. Maybe something needs to be cleared in UnlinkInner() too?
Attachment #8609607 - Flags: feedback?(continuation)
> As far as I can tell, the only place where mOwningNode is set is > nsStyleLinkElement::SetStyleSheet() And the CSSStyleSheet cloning constructor, yes? I think the relevant big here is that if you look at nsStyleLinkElement, it just nulls out mStyleSheet in Unlink. It doesn't SetStyleSheet(nullptr) until the destructor. This seems pretty broken to me, actually. Seems to me that if we end up doing nsStyleLinkElement::Unlink while it has a non-null mStyleSheet then that will cause the old mStyleSheet value to have a dangling pointer to the nsStyleLinkElement, no? We should probably SetStyleSheet(nullptr) in nsStyleLinkElement::Unlink.
One other thing to watch out for here, though: stylesheets are kept alive for the lifetime of the document. We should check whether making this a strong ref would cause document-lifetime leaks of nodes.
With regard to the Unlink change, that makes sense to me, but feels like it should be a separate bug. The style sheets being kept alive for the lifetime of the document thing is actually probably the cause of the problem with this patch. The owning node element may be kept alive for too long, causing the leaked until shutdown problem.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: