Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-05-03 13:52:18

Frank Mori Hess:

> What I'm thinking is more along the lines of how a weak_ptr goes from
> "expired" to "good". Currently, that can only happen by assignment of a
> new shared_ptr. And assignment of one expired weak_ptr has no effect on
> any copies of the weak_ptr, they stay expired.

This is correct as far as it goes. But in the case I showed, no assignment
happens to any of the weak_ptr instances. Consider how weak_ptrs go from
use_count of 1 to use_count of 0 without any assignment. This is the same
event in reverse. It can't normally occur now, of course.

Remember that use_count() does not report the state of a particular
instance, it reports program-wide state (the number of shared_ptr instances
sharing ownership with *this). It can and will go up and down without any
changes to *this.

> Yes, but in the case of a long-lived signal with many short-lived
> connections, it would effectively create a resource leak when relying on
> automatic connection management.

Well, there would be no automatic connection management, so obviously
relying on it would be a bad idea. :-) One would have to use scoped
connections or manual disconnects in the destructor, as usual.

Boost list run by bdawes at, gregod at, cpdaniel at, john at