I was trying to write a caption for this question like 10 minutes and as you will see I eventually failed.
I was reading Sutter's blog and the topic is using std::make_shared and its cons and pros. Please see the photo attached:
This is a small part of a very very interesting alticle which I highly recommend to read. So my question is regarding this sentence: A “weak reference” count to track the number of weak_ptrs currently observing the object. The shared housekeeping control block is destroyed and deallocated (and the shared object is deallocated if it was not already) when the last weak reference goes away.
So I cant really inderstand this statement. Initially when we create a std::shared_ptr by make_shared like auto sp1 = make_shared<widget>();, there are no weak ptrs currently observing the sp1. So it will be deleted just after this like by the logic I understand. Can anyone explain this to me please?

Aucun commentaire:
Enregistrer un commentaire