Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-10-01 08:08:12


From: "Petr Ferschmann" <petr_at_[hidden]>
> Thank you for your answer.
>
> I know that intrusive_ptr is not documented yet.
>
> But in documentation of weak_ptr is written that when all shared_ptr are
> destroyed all weak_ptr are set to 0. And it of course works in that style
for
> normal shared pointer.

If you test the weak_ptr, you'll see that it will properly report that it's
expired(); use_count() will be zero; and if you try to construct a
shared_ptr from it, the construction will fail.

> But when I am using weak_ptr with intrusive_ptr it know works like normal
> pointer?
>
> I think I missed something. Is it bug or feature?

It is a "feature". The reference count is contained in counted_base, and
it's embedded into the object. It is not possible to destroy the object
without also destroying the counted_base, and this cannot happen while there
are still weak pointers to that counted_base. That's why
counted_base::dispose() is invoked when the last shared_ptr is destroyed, to
let you release the resources contained in your object.


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