Skip to content

Destroy plugin instances before their class loader (kilted) - #352

Open
MatthijsBurgh wants to merge 1 commit into
ros-visualization:kiltedfrom
MatthijsBurgh:fix/kilted/destroy-instances-before-class-loader
Open

MatthijsBurgh wants to merge 1 commit into
ros-visualization:kiltedfrom
MatthijsBurgh:fix/kilted/destroy-instances-before-class-loader

Conversation

@MatthijsBurgh

Copy link
Copy Markdown
Contributor

Problem

Closing rqt with a C++ plugin loaded prints this on every shutdown:

Warning: class_loader.ClassLoader: SEVERE WARNING!!! Attempting to unload library while objects created by this loader exist in the heap! You should delete your objects before attempting to unload the library or destroying the ClassLoader. The library will NOT be unloaded.
         at line 127 in ./src/class_loader.cpp

Reproduce: rqt --standalone rqt_image_view, then close it (or Ctrl+C).

Cause

On application close, plugins are shut down but not unloaded, so RosPluginlibPluginProvider still holds their shared_ptrs in instances_. Its destructor deletes class_loader_ in the destructor body, while instances_ and libraries_to_unload_ are members and are only destroyed after the body. The class loader is therefore asked to unload the plugin library while the plugin object is still alive.

A gdb backtrace at the warning shows the path (library being unloaded: librqt_image_view.so):

class_loader::ClassLoader::unloadLibraryInternal(bool)
class_loader::MultiLibraryClassLoader::unloadLibrary(...)
class_loader::MultiLibraryClassLoader::shutdownAllClassLoaders()
class_loader::MultiLibraryClassLoader::~MultiLibraryClassLoader()
...
rqt_gui_cpp::NodeletPluginProvider::~NodeletPluginProvider()
qt_gui_cpp::CompositePluginProvider::~CompositePluginProvider()
rqt_gui_cpp::RosCppPluginProvider::~RosCppPluginProvider()

Fix

Clear libraries_to_unload_ and instances_ in the destructor before deleting the class loader.

rolling does not need this: since #339 class_loader_ is a unique_ptr declared before the two containers, so the instances are already destroyed first. I checked a current rolling install (qt_gui_cpp 3.0.4) and it does not print the warning. That is why this targets kilted directly instead of going through rolling. The same change is proposed for the other affected branches (jazzy, kilted, lyrical).

Testing

On the ros:kilted-ros-base container (qt_gui_cpp 2.9.3, class_loader 2.8.1), running QT_QPA_PLATFORM=offscreen rqt --standalone rqt_image_view and stopping it with SIGINT:

  • released binaries: warning printed in 3 of 3 runs
  • qt_gui_cpp and rqt_gui_cpp rebuilt with this change: warning printed in 0 of 3 runs

rqt_gui_cpp has to be rebuilt as well, since it instantiates the template from this header.

🤖 Generated with Claude Code

~RosPluginlibPluginProvider() deleted the class loader in the destructor
body, while the plugin instances in instances_ and libraries_to_unload_
are members and therefore were only destroyed afterwards. On closing rqt
with a C++ plugin loaded, class_loader then reported:

  SEVERE WARNING!!! Attempting to unload library while objects created
  by this loader exist in the heap!

Release the instances first. rolling already has this order since ros-visualization#339.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Matthijs van der Burgh <matthijs.van.der.burgh@vbti.nl>
@mergify

mergify Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant