Re: [sigc] sigc slot & shared_ptr anti-pattern



On Thu, 2006-08-24 at 10:36 -0500, Paul Davis wrote:
> Paul Davis wrote:
> > below is a tiny program that demonstrates either an anti-pattern or a
> > bug or both in the use/design of libsigc++. the program will generally
> > run normally, but using valgrind reveals something deeply wrong, as
> > noted in the annotations in the code.
> >   
> Paul,
> 
> Fixed:

not really, weak_ptr<> has the wrong semantics here. i think. 

> As b goes out of scope, new B gets deleted as normal.
> Now, as the slot gets destroyed its just a weak_ptr, no double delete.
> 
> I'm not exactly sure how you managed to get the double delete with a 
> shared_ptr. And I'm kind of wired and caught up in my own software stuff 
> at the moment right now, but I once read about using weak_ptr's to 
> remove cyclic dependencies.

its not a double delete of the T in shared_ptr<T>, its a double delete
of a slot. This happens the slot is deleted by both the Signal and the
slot owner. or so it appears. the cyclic dependency here, such as it is,
is at the slot level, not the shared_ptr<> level.

> I'm not sure where the problem is. If its sigc or boost.  I'm guessing 
> its just a weird corner case between the usage.

i suspect so too, but its causing catastrophes in my code as we move
over to use shared_ptr<> everywhere.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]