Cleaning dynamic memory allocation in a call back function.
Hi, My callback function looks like this.
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input_pc)
{
// Convert the sensor_msgs/PointCloud2 data to pcl/PointCloud - Dataset
pcl::PointCloud<PointT>::Ptr cloud_in(new pcl::PointCloud<PointT>);
pcl::fromROSMsg(*input, *cloud_in);
// pcl::norms
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
....
....
for(auto searchPoint: filtered_cloud->points)
{
pcl::PCA<PointT> local_pca = new pcl::PCA<PointT>;
pcl::PointIndices::Ptr inliers(new pcl::PointIndices());
....
....
delete local_pca;
delete inliers;
}
publisher(*cloud_normals);
// delete cloud;
// delete cloud_normals;
}
Is it a good practice to de-allocate memory for the variables "cloud" , "cloud_normals" after the end of callback function ?