Open
Bug 802179
Opened 13 years ago
Updated 3 years ago
Add a nice way to use strong pointers without causing things to be added to the purple buffer
Categories
(Core :: Cycle Collector, defect)
Core
Cycle Collector
Tracking
()
NEW
People
(Reporter: mccr8, Unassigned)
Details
In cycle collector code, there are a number of places where we need to get a strong pointer to an object, for instance, due to a QI, but the object is definitely alive when we Release() it, so we want to make sure it isn't in the purple buffer when we're done, to reduce the size of the CC graph.
The current approach looks like:
nsCOMPtr<nsIFoo> strongx = do_QI(...);
nsIFoo *x = strongx;
strongx = nullptr;
// remove x from the purple buffer, use x
It isn't obvious what is happening here.
One approach would be to add a subclass of nsCOMPtr called something like nsUnpurpleCOMPtr that does UnmarkIfPurple() after its Release().
Then the above would become:
nsUnpurpleCOMPtr<nsIFoo> x = do_QI(...);
// use x
Another approach would be to add some kind of UnpurpleForget() method to nsCOMPtr, and manually call it on every exit path from the scope of x. That would probably require less changes, but is more annoying to use.
Whatever we do, we need some scary warnings in comments, because if x isn't actually definitely alive when we unpurple it, it will leak. We could possibly assert CanSkipThis() or something in the destructor.
Either of these will cause the object to be added to the purple buffer, then immediately removed, but that should be fairly cheap now, so accepting that seems better than adding a ReleaseWithoutPurpling() kind of method to nsCycleCollectingRefCount.
One example of this is bug 801719, but we've had a few here and there (XPConnect?) we should try to them down and update them to whatever we decide.
Updated•3 years ago
|
Severity: normal → S3
| Reporter | ||
Updated•3 years ago
|
Component: XPCOM → Cycle Collector
You need to log in
before you can comment on or make changes to this bug.
Description
•