Reputation: 649
I was reading the following documentation - https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/weak-references#safely-accessing-the-this-pointer-in-a-class-member-coroutine
I understand that weak/strong ref is needed so that we do not dereference deleted object (this) in a coroutine. So, if there is a co_await statement in a coroutine and I am referencing a class member (function or data member) after that co_await, do I always have to have strong/weak ref? Or are there cases where we can skip it?
One example in the doc mentioned is around event source and event recipient lifetime such that when source triggers event, if recipient is guaranteed to be alive, we can skip capturing this by strong//weak ref.
Is there a such case in case of plain coroutine or do I always have to take a ref?
Upvotes: 0
Views: 302