[webkit-dev] Stop Using Raw Pointers & References in New Code
Michael Catanzaro
mcatanzaro at redhat.com
Fri Jan 27 08:52:52 PST 2023
On Tue, Jan 24 2023 at 02:53:42 PM -0600, Michael Catanzaro
<mcatanzaro at redhat.com> wrote:
> E.g. for GObjects, we could write GWeakPtr, but this would not be
> very ergonomic, and it won't work for arbitrary types.
So Carlos Garcia added this in https://commits.webkit.org/259482@main.
There is a downside to GWeakPtr: global locking. Even though GWeakPtr
is not threadsafe and each GObject keeps its own list of weak
locations, all GObjects nonetheless share the same global lock for weak
pointer locations. There is probably a relatively high cost compared to
WTF::WeakPtr, so I'd say it should be used only when it provides
valuable safety (e.g. in member variables) rather than spammed (e.g. in
local variables).
Michael
More information about the webkit-dev
mailing list