On Wed, Jan 25, 2023 at 5:54 AM Michael Catanzaro via webkit-dev < webkit-dev@lists.webkit.org> wrote:
> > Thinking about this more, I'm not sure this plan works for WeakPtrs? > Say we have: > > WeakPtr<Foo> f = /* initialized somehow */; > if (Foo* f = f.get()) > { > // do something > } > > Then we already broke the rule against using a raw pointer in a local > variable. That's the only way to use a WeakPtr, so we kind of have to, > but as long as you have it stored in a raw pointer, then we gain no > additional safety from the WeakPtr. CheckedPtr would work better in > local variables, but again that's not an option for types we don't > control. > We need to keep a RefPtr<Foo> to do something. if (RefPtr f = f.get()) It's not a problem of the circular dependency in this case because the local variable will be destructed soon. The problem of WeakPtr is that it may return a pointer of half-destructed Foo object if this code is called during the Foo destructor. This is being discussed in https://github.com/WebKit/WebKit/pull/8748 .
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-dev