You must understand that generic pointers are implemented using a reference counter, which means that if you have loops in your pointer graph, objects will not be released. That is, if points b and b point to a, but nothing points to a or b, then neither one nor b will be freed, because they both have a reference count of '1'.
Boost provides weak pointers to get around this, which allows you to store a pointer to a shared object without increasing its number of references. Weak pointers provide a level of security in that trying to dereference a pointer after releasing a shared pointer will throw an exception rather than a program crash.
Generic pointers are also quite expensive (at least compared to the raw pointer) in terms of performance - but it's better to use them and then delete them as soon as the profiler identifies a bottleneck rather than using them everywhere.
In addition, yes, they are very useful for managing dynamically allocated objects.
Edit: Another problem (mentioned on the promotion pages) is to avoid the “temporary” shared_pointers:
func(A(), boost::shared_ptr<B>(new B));
because the compiler is allowed to optimize it as
tmp1 = new B; tmp2 = A(); tmp3 = boost::shared_ptr<B>(tmp1) func(tmp2,tmp3)
which may look normal at first glance, but if A () throws an exception, then B was thrown, but shared_ptr had not yet received it, so the pointer is never freed.
Adam bowen
source share