Thanks for the extended explanation. Using boost::weak_ptr<> makes a good deal of sense in the situations which you specified. bjorn.karlsson@readsoft.com wrote:
From: Edward Diener [mailto:eddielee@tropicsoft.com]
I don't understand what the practical use of Boost weak_ptr<> is ? Anyone like to clue me in ? I understand that Boost weak_ptr<> creates an internal reference to a Boost shared_ptr<> but I don't understand what that is supposed to accomplish.
A weak_ptr is an observer of the pointee, i.e it doesn't take part of the lifetime management of the resource. One use for it is to break cyclic dependencies; another is to avoid dangling pointers. When a shared_ptr deallocates its pointee, it notifies the weak_ptrs. When the weak_ptr is subsequently used, it knows that the resource is gone (compare this with storing raw pointers, where there is no way to tell whether the pointer is still valid or not). snip...