Boost logo

Boost Users :

From: Edward Diener (eddielee_at_[hidden])
Date: 2003-04-15 06:01:03


Thanks for the extended explanation. Using boost::weak_ptr<> makes a good
deal of sense in the situations which you specified.

bjorn.karlsson_at_[hidden] wrote:
>> From: Edward Diener [mailto:eddielee_at_[hidden]]
>>
>> 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...


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net