Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-22 09:28:28


From: "Peter Dimov" <pdimov_at_[hidden]>

> From: "David Abrahams" <dave_at_[hidden]>
> >
> > If you derive from counted_base, what happens with weak_ptr?
> > It seems as though every live weak_ptr ends up keeping the object
alive...
>
> Weak pointers to intrusive counted objects require a bit of help from the
> user. As the count and the object are inseparable, a weak_ptr will keep
the
> whole object alive. However, counted_base::dispose will be called when
the
> use count drops to zero and only weak pointers to the object remain. If
the
> object manages any resources, it should override dispose() and release
them.
> An important special case is that any shared_ptr members should be
reset(),
> or potentuial cycles won't be broken.

Thanks, that's interesting. Also, I suppose, weak_ptr members /should/ be
reset for optimal behavior.
All this definitely pushes me towards using a free-function interface to
avoid the problem that 'this' cannot be a smart pointer. Seems like a much
cleaner approach to me.

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk