diff --git a/nav2_costmap_2d/src/costmap_2d_ros.cpp b/nav2_costmap_2d/src/costmap_2d_ros.cpp index feedb552c2..0d7b442a8a 100644 --- a/nav2_costmap_2d/src/costmap_2d_ros.cpp +++ b/nav2_costmap_2d/src/costmap_2d_ros.cpp @@ -338,9 +338,7 @@ Costmap2DROS::on_cleanup(const rclcpp_lifecycle::State & /*state*/) costmap_publisher_.reset(); clear_costmap_service_.reset(); - for (auto & layer_pub : layer_publishers_) { - layer_pub.reset(); - } + layer_publishers_.clear(); layered_costmap_.reset();