Closed
Bug 43656
Opened 25 years ago
Closed 24 years ago
Patch to fix shutdown leak noise in nsStyleSet
Categories
(Core :: Layout, defect, P3)
Tracking
()
VERIFIED
FIXED
People
(Reporter: inaky.gonzalez, Assigned: inaky.gonzalez)
References
Details
(Keywords: memory-leak, Whiteboard: [tind-mlk])
Attachments
(4 files)
4.13 KB,
patch
|
Details | Diff | Splinter Review | |
2.32 KB,
patch
|
Details | Diff | Splinter Review | |
2.55 KB,
patch
|
Details | Diff | Splinter Review | |
2.45 KB,
patch
|
Details | Diff | Splinter Review |
Class nsStyleSet references a nsStr in static variable
nStyleSet::GetStringValueXXX::theStr. Upon shutdown it causes some
noise, as it is not released. Following the directions I got in
#38283, I implemented a fix which will shut it down on XPCOM shutdown,
by turning nsStyleSet into an nsIObserver.
As this is only useful for noise reduction during debugging (and
I don´t thinkit makes world better to have it in production releases),
the fix is only activated if DEBUG is defined. In case you want this
changed, let me know.
Please see the attached patch for the fix.
Assignee | ||
Updated•25 years ago
|
Assignee | ||
Comment 1•25 years ago
|
||
Comment 2•25 years ago
|
||
inaki: I think the use of XPCOM shutdown is overkill in this case. If this is a
global object that's allocated once for efficiency's sake, I'd recommend that
you add a global static counter as a member in nsStyleSet.
- Increment it in each ctor: if the count is one, you'll need to (re-)create the
object.
- Decrement it in each dtor. When it goes to zero, release the object
This is a more common (and much simpler) pattern than using an XPCOM shutdown
listener. For an example, see
http://lxr.mozilla.org/mozilla/source/rdf/content/src/nsXULElement.cpp#328
http://lxr.mozilla.org/mozilla/source/rdf/content/src/nsXULElement.cpp#395
thanks,
chris
Comment 3•25 years ago
|
||
Wait a minute: this looks like a dup of bug 43579, and I have attached a patch
to that bug to fix this problem. The easiest approach is to just make the URI
instance a data member on the StyleSet and manage it as a normal data member,
giving up the static-nature of it but still avoiding a new/delete for each call
of to EnableQuirkStyleSheet.
Chris' apprach is good too, better in the sense that it does not bind the
lifetime of the URL instance to each style set, and I'd be all for that
implementation too.
I think this bug should be Dup'd to 43579, or 43579 should be dup'd to this one.
Comment 4•25 years ago
|
||
I kind of like the xpcom shutdown method better. Less chance for refcounts to
get screwed up.
Assignee | ||
Comment 5•25 years ago
|
||
Completely agree, Chris ... I am changing all my patches for this kind of
problems to use global in-class counters.
Marc, I prefer Chris´s fix. We still have static, not reallocated each time and
should work almost the same.
Just a damn pity we cannot have those static COMPtrs ...
Comment 6•25 years ago
|
||
What's wrong with the callback-based approach? I think it's a lot less error
prone. With the global counters, you end up with a domino effect if something
doesn't get freed.
Assignee | ||
Comment 7•25 years ago
|
||
My english is again hitting my head. WHat do you mean with ´callback based
approach´? If it is the XPCOM sollution, I do too, but I agree with Chris that
it is too overkill for these kind of problems. Take into account that we are
only taking noise away, to help us debugging, but we are in no way enhancing
runtime, we are only affecting shutdown.
Going to re-create this using a instance counter. Please tell me if you guys
agree.
Do we even need to keep this as static? See bug 43579.
Assignee | ||
Comment 10•25 years ago
|
||
Well, if we don´t do, we´ll have around 8 nsStyleSets (as you comment), we are
spending more time in creating and managing them then managing through an static
object.
And that should be TRTTD (tm) ... :)
Comment 11•25 years ago
|
||
TRTTD? Que?
Assignee | ||
Comment 12•25 years ago
|
||
Mande lo cualo?
TRTTD = The Right Thing To Do ... you know, when you want to sound pedantic but
not to make it too evident ... :)
Comment 13•25 years ago
|
||
By "callback" I meant using NS_IMPL_NSGETMODULE_WITH_DTOR, supplying a
destructor to clean up the objects in question.
BTW, I noticed that you've got your stuff ifdef DEBUG -- any reason why we
shouldn't do it for release builds too just to keep it simple.
Assignee | ||
Comment 14•25 years ago
|
||
[callback]
huh ... looks like I didn´t go to class the day they explained that. Could you
ellaborate some more on it.
[ifdef DEBUG]
As this is really useful only for debug builds (taking out noise), I just
thought it could be worth comenting it out on release ones, but in the new
patches I´m not doing it; as you say, we make it simpler.
Assignee | ||
Comment 15•25 years ago
|
||
Comment 16•25 years ago
|
||
The patch looks fine. I would name the URI instance gQuirkURI instead of gURI,
and maybe check for gQuirkURI != nsnull before calling
cssSheet->ContainsStyleSheet(gUrl ...) because asserting that memory is
available is dubious at best. But other than that it looks nice.
Thanks, Inaky.
Assignee | ||
Comment 17•25 years ago
|
||
Ok, done. I had the check on gQuirkURI not being NULL in my previous patch, I
forgot to re-generate it.
Assignee | ||
Comment 18•25 years ago
|
||
Whiteboard: [tind-mlk]
Comment 19•25 years ago
|
||
did this die? should it get reviewed for checkin again?
Comment 21•24 years ago
|
||
Thanks! The patch looks good. r=attinasi@netscape.com
Comment 22•24 years ago
|
||
sr=brendan@mozilla.org on that last patch.
/be
Fix checked in 2000-11-07 19:13 PDT.
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•