I create an object in a main function as a std::shared_ptr object and want to save some information of it in its destructor. However I found out, that the destructor of the object is never called. Can I manually ensure, that the destructor is called? And does anybody know, why the destructor is never called? Does this has something to do with ros2?
Here some code: main.cpp:
#include "q_learner/q_learner_node.h"
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::executors::MultiThreadedExecutor exec;
auto q_learner_node = std::make_shared<q_learner::QLearnerNode>();`//This is the object that never gets destructed.
exec.add_node(q_learner_node);
exec.spin();
rclcpp::shutdown();
return 0;
}
And q_learner_node.cpp:
QLearnerNode::QLearnerNode() : rclcpp::Node("q_learner_node"){
// ... some stuf ...
}
QLearnerNode::~QLearnerNode(){
std::cout << "Destructor called" << std::endl;
// ... some other stuff ...
}
// some more stuff
and q_learner_node.h:
class QLearnerNode : public rclcpp::Node
{
public:
QLearnerNode();
~QLearnerNode();
private:
// some more stuff
};
Or is it a problem of base-class / child-class?
EDIT:
I did not know this, so google gave me a hint just now:
I'm using "Ctrl+C" To exit the process in terminal. However rclcpp should provide a signal_handler to handle those signals. This does not seem to work for me. I'm still seaarching, but any hints would be great. I found this github issue from 2018, but it should not make problems in my code (I think/ hope).