Memory leak using the pcl passthrough filter
Dear ROS users, I want to use the pcl passthrough filter in a callback and then publish the filtered cloud. The code works but I have a problem with the memory. It always increases. It means that the callback allocate every time new memory. Here the code:
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg){
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
pcl_conversions::toPCL(*cloud_msg, *cloud);
pcl::PCLPointCloud2* cloud_passthrough_filtered = new pcl::PCLPointCloud2(*cloud);
pcl::PCLPointCloud2ConstPtr pass_cloudPtr(cloud_passthrough_filtered);
pcl::PassThrough<pcl::PCLPointCloud2> pass;
pass.setInputCloud(pass_cloudPtr);
pass.setFilterFieldName("z");
pass.setFilterLimits(_passthrough_z_min, _passthrough_z_max);
pass.filter(*cloud_passthrough_filtered);
pass.setFilterFieldName("x");
pass.setFilterLimits(_passthrough_x_min, _passthrough_x_max);
pass.filter(*cloud_passthrough_filtered);
pass.setFilterFieldName("y");
pass.setFilterLimits(_passthrough_y_min, _passthrough_y_max);
pass.filter(*cloud_passthrough_filtered);
// Convert to ROS data type
sensor_msgs::PointCloud2 output;
pcl_conversions::fromPCL(*cloud_passthrough_filtered, output);
pub.publish (output);
delete cloud;
}
I think the problem is on the second "new", but I cannot delete it at the end, otherwise the program crashes. I think this is a very standard code. Where is the mistake? Thanks for your help!
Asked by rastaxe on 2016-02-17 13:09:58 UTC
Comments
Did you find a solution to your problem yet? Would be interesting for me as well...
Asked by Eb_Jon on 2016-05-31 07:30:44 UTC