Boost logo

Boost Users :

Subject: [Boost-users] [smart_ptr]intrusive_ptr suggestion
From: gast128 (gast128_at_[hidden])
Date: 2010-08-11 16:01:05


Hello all,

probably not a good time to post during the stress of 1.44 release.

We use boost a lot and also the intrusive_ptr to wrap ref counted objects.
However the intuitive behavior gives memory leaks. For example use a ref
counted object KFoo:

intrusive_ptr<IFoo> ptr(new KFoo); // mleak, KFoo is extra ref counted
ptr.reset(new KFoo) //mleak

ptr = intrusive_ptr<IFoo>(new KFoo, false); //ok, but Spartan way of writing

Above examples are all in contrast with the syntax of shared_ptr's, in which
one could write it in above way without leaking. Although the constructor of
intrusive_ptr has an extra argument, its default is set on true.

Wouldn't it be a nice suggestion to create a function like make_intrusive, so
that one could write:

ptr = make_intrusive<KFoo>();

It seems so basic that there must be a hidden caveat somewhere...


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