2

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).

4

1 回答 1

0

我不知道究竟是什么导致了这种行为,但是在重置工作区并从头开始构建所有内容后,它工作了......

于 2019-10-31T16:10:51.590 回答