Understanding weak reference counter
c++, c++11, smart-pointers
Solution
There are two objects associated with `shared_ptr<T>` & `weak_ptr<T>`:
- the actual object (`T`)
- the control block, that contains the shared and weak counters
The actual object will be destroyed, if the shared counter reaches `0`. But the control block has to stay alive as long as there are shared or weak pointers, i.e. the control block will be deleted as soon as both the shared and weak counter are `0`.
Problem
When creating shared_ptr it's manager object uses strong & weak reference counters. I understand that by using strong reference counter shared_ptr knows when to deallocate the managed object but I don't understand why is it using weak reference counter.