Why use a std::weak_ptr to capture a publisher in a lambda used as a callback?
Hi! On line 35 of the intraprocessing demo here, how come a std::weak_ptr
is used to capture the node's publisher? How come it is not sufficient/recommended to simply capture the entire node ([this]
)?
My understanding of std::weak_ptr
is that they should be used in situations where std::shared_ptr
pointers can dangle, but since the callback will only ever be executed in the context of the node's lifetime (I think) and the std::shared_ptr
to the publisher should never dangle, what is the point of using std::weak_ptr
?
I'm using ROS2 Dashing on an NVIDIA Jetson Nano running Ubuntu 18.04.
Thank you!