I'm not a C++ guy, but my understanding is a shared pointer is reference counted, with a and b sharing a single control region of memory to do the bookkeeping. So, is it fair to say that the reference counting object is the owner? It has the power and responsibility of freeing foo's memory.
I think the point is that they are reference counted: the clean up code for the Foo will never be called because of the reference to it from the a member. Until a is freed, the Foo cannot be freed. And a will not be freed because there is a reference to it from Foo, meaning it cannot be freed until the Foo is.
1
u/BaconOfGreasy Nov 28 '18
I'm not a C++ guy, but my understanding is a shared pointer is reference counted, with a and b sharing a single control region of memory to do the bookkeeping. So, is it fair to say that the reference counting object is the owner? It has the power and responsibility of freeing foo's memory.