BewareMyPower commented on code in PR #17395:
URL: https://github.com/apache/pulsar/pull/17395#discussion_r962337056


##########
pulsar-client-cpp/lib/PeriodicTask.cc:
##########
@@ -27,9 +27,14 @@ void PeriodicTask::start() {
     }
     state_ = Ready;
     if (periodMs_ >= 0) {
-        auto self = shared_from_this();
+        std::weak_ptr<PeriodicTask> weakSelf{shared_from_this()};
         timer_.expires_from_now(boost::posix_time::millisec(periodMs_));
-        timer_.async_wait([this, self](const ErrorCode& ec) { 
handleTimeout(ec); });
+        timer_.async_wait([weakSelf](const ErrorCode& ec) {

Review Comment:
   I didn't get it why did you mention the destructor. Using `weak_ptr` here is 
to avoid a cyclic reference count case. Each object managed by a `shared_ptr` 
could cause cyclic reference. Using `weak_ptr` is a best practice for it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to