How does std::shared_ptr work, and how is the reference counter synchronized between objects?

Last updated 21 June 2026

  • std::shared_ptr shares a separately allocated control block holding the strong count, weak count, managed pointer, and deleter.

  • Copies increment the strong count and destruction decrements it. At 0 the object is destroyed, and the control block lives until the weak count also reaches 0.

  • Counts are updated atomically, so copying/destroying across threads is safe. The pointee and the shared_ptr instance itself are not synchronized and need your own locking.

  • https://www.geeksforgeeks.org/dsa/types-of-pointer-in-programming/
  • https://www.geeksforgeeks.org/cpp/shared_ptr-in-cpp/
  • https://www.geeksforgeeks.org/questions/which-of-the-following-statements-about-smart-pointers-in-1/
  • https://www.interviewbit.com/cpp-interview-questions/
All C++ interview questions