[ros-users] Draft REP: Automatic unloading of libraries for pluginlib

Dirk Thomas dthomas at willowgarage.com
Fri Feb 10 18:46:04 UTC 2012


On 10.02.2012 04:32, Lorenz Mösenlechner wrote:

> On Fri, Feb 10, 2012 at 2:06 AM, Patrick Mihelich <mihelich at willowgarage.com <mailto:mihelich at willowgarage.com>> wrote:
>
>     On Thu, Feb 9, 2012 at 12:55 PM, Dirk Thomas <dthomas at willowgarage.com <mailto:dthomas at willowgarage.com>> wrote:
>
>             While I like boost::shared_ptr, it is not always possible to use it nicely.
>
>             In rviz I have plugin classes which are subclasses of QWidget (from Qt GUI library).  These objects are automatically deleted by Qt when their parent widgets are deleted.  I can be
>             notified of their
>             deletion by Qt, and call an "unload" or "decrement-reference-count" function, but it is not easy to use these QWidget pointers inside boost::shared_ptr without getting double-deletion crashes.
>
>
>         That sounds like a very reasonable use case.
>         Automatically deleting and unloading is a nice feature but might not always be desired.
>         Having the option to get a raw pointer (as before) and take care of garbaging stuff manually would be great.
>
>
>     I don't like this, but don't see a clearly better solution.
>
>
> 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.

Dirk



More information about the ros-users mailing list