On Fri, Feb 10, 2012 at 10:46 AM, Dirk Thomas <dthomas@willowgarage.com> wrote:
On 10.02.2012 04:32, Lorenz Mösenlechner wrote:
I actually think you still can use a shared pointer in that case. shared_ptr has a overloaded constructor that takes an explicit delete functor. When the reference count reaches zero, instead of
calling delete, the functor is called.
I'm not sure if that helps here, but I think this is at least a possibility to consider. Instead of returning a normal pointer where the user has to calll decrement-reference-count manually, it should
be possible to just have a share_ptr deleter that calls the decrement-ref-count function.
Technically yes, that would be possible.
It would make the method signature much easier.
We use the deleter for the createInstance() method which performs deleting the instance as well as decrementing reference count.
But would it be obvious for a user that a method like:
boost::shared_ptr<T> createUnmanagedInstance(const std::string& lookup_name)
does NOT delete the instance when it runs out of scope?
The API doc can state that fact clearly, but I think the return value gives the user a wrong impression how it is intended to be used.