Boost logo

Boost Users :

Subject: Re: [Boost-users] how to delete references to objects from a container...
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2009-12-09 11:26:06

rv_nath wrote:
> Dear Jeff,
> Thanx for your quick reply. FUrther to the same question,
> can you please explain:
> > There is also weak_ptr originally intended to break cycles which may be
> of use to you.
> - the meaning of breaking cycles, and how it can help in this situation.
> It is said that a weak ptr doesn't increment the refcount. That means there
> is a possibility of the pointee object being deleted, while a weak ptr is
> holding a reference of it. So, in my understanding, if i return a weak-ptr
> to the clients of my object, then I will be able to delete my object at time
> of my choosing inspite of how many number of weak-ptr references the clients
> may have. But after this, the weak-ptr reference becomes invalid. Am I
> right?

(please don't top post)

Yes, that's right.


You'd have to lock the weak_ptr to access a shared_ptr to the resource,
which would litter your code with a lot of conditionals to check to see
if the shared_ptr is not null. While this may be a valid design approach
in some cases, my first inclination would be to redesign taking into
account the true nature of the relationships your dealing with, IMHO of


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at