Boost logo

Boost Users :

Subject: Re: [Boost-users] bind with weak_ptr
From: Christopher Pisz (cpisz_at_[hidden])
Date: 2011-10-10 14:05:50


Igor R <boost.lists <at> gmail.com> writes:

>
> > I see many posts when I google this problem. I wonder, since most of them
are
> > dated 1.35 and previous, if there was ever a solution to this problem?
> >
> > I think this fellow says it best when he posted,
> > "My problem is, that when i bind member functions, if i specify the
instance
> > of the class as a shared_ptr, then i get memory leaks because the binding's
> > shared_ptr to the instance keeps it alive, and it potentially produces
cyclic
> > references that in the current model, would be complicated to break.
> >
> > And of course, if i use raw pointers to the binding instances, then i'll
get a
> > crash if the instance has been destroyed and i try to execute the binding
> > function.
> >
> > So what i would need, is to use bind with weak pointers, and just do
nothing
> > if locking it fails."
> >
> > http://www.gamedev.net/topic/494089-help-boostbind-and-shared-pointers/
> >
> >
> > I've almost went to just using raw pointers and letting the program crash
if
> > the instance to which the member bound no longer exists. I hate to do that.
>
> Have you looked at the link I posted as an answer to one of your
> previous questions on the subj?
> http://article.gmane.org/gmane.comp.lib.boost.user/70699
> Doesn't it do exactly what you want?
>

I read the article. Sadly, I cannot even begin to follow the code.

I also tried going back to raw pointers and now I get unhandled exceptions
rather than the problem with destructors not getting called :/ I am debugging
that now and trying to track it down.

What a pain.

So, boost has not built this in yet then, even though there seems to be an
aweful lot of demand for it?


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