title: Why shared_ptr's reference counting object needs to keep track of the number of weak_ptrs pointing to the object too?
body: <p>Hi I am reading through <a href="http://umich.edu/~eecs381/handouts/C++11_smart_ptrs.pdf" rel="noreferrer">this document</a> and some other documents about C++'s <code>shared_ptr</code> and they all seem to suggest that apart from the number of <code>shared_ptr</code> pointing to the allocated object, the reference count object has to keep track of how many <code>weak_ptr</code> pointer pointing to the object as well. My question is why? From my understanding, <code>weak_ptr</code> is non-owning so if the count of <code>shared_ptr</code> pointing to the object reaches zero the object can be deleted. That is why sometimes we need to use <a href="http://en.cppreference.com/w/cpp/memory/weak_ptr/expired" rel="noreferrer">expired</a> to check the availability of an object pointed by a <code>weak_ptr</code>. Could you explain the reason for needing to keep track of the number of <code>weak_ptr</code>s?</p>
  
  <p>Why do we need weak count here?
  <a href="https://i.stack.imgur.com/YNNI5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YNNI5.png" alt="enter image description here"></a></p>