Understanding a weak reference counter

When creating shared_ptr, the manager object uses strong and weak reference counters. I understand that using a strong reference counter, shared_ptr knows when to free a managed entity, but I don’t understand why it uses a weak reference counter.

+4
source share
3 answers

There are two objects associated with shared_ptr<T>and weak_ptr<T>:

  • actual object ( T)
  • control unit containing common and weak counters

, 0. , , .. , 0.

+5

.

, . 0, , , . .

, .

, . , , , .

+3

weak_ptr , , , . , - , , .

+1

Source: https://habr.com/ru/post/1548662/


All Articles