From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-22 09:15:16
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.
The current implementation has a defect since shared_ptr::reset() is not
guaranteed to never throw, but counted_base::dispose is. This will be fixed
in the next release.
> It also seems as though there's some danger of inadvertently overriding
> undocumented virtual functions in counted_base.
counted_base will be fully documented in the next release, including the
above explanation for weak pointers to counted_base-derived objects.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk