title: How does a reference-counting smart pointer's reference counting work?
body: <p>In other words, how does the implementation keeps track of the count?</p>
  
  <p>Is there a map-like object maintained which is accessible by all the <code>shared_ptr</code> instances whose key is the pointer's address and value is the number of references? If I've to implement a <code>shared_ptr</code>, this is the first idea that's coming to my mind.</p>
  
  <p>Is there a possibility for a memory leak in case of these reference-counting smart pointers? If so, how can I avoid them?</p>