A control block of a shared_ptr
is kept alive while there is at least one weak_ptr
present. If the shared pointer was created with make_shared
that implies that the whole memory of the object is kept allocated. (The object itself is properly destructed, but since the control block and the memory for the object were allocated in one chunk, as make_shared
does, they can only be deallocated together.)
Is my understanding correct?
It seems that this behaviour represents a problem, for example in the famous "cache example". The memory for the objects will be kept allocated forever.
It it a problem in any practical situations? Shall the shared_ptr
be created using a constructor in such a situation (large object and intent to use weak_ptr
s)?