Memory leak using the pcl passthrough filter

asked 2016-02-17 12:09:58 -0500

rastaxe gravatar image

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!

edit retag flag offensive close merge delete

Comments

Did you find a solution to your problem yet? Would be interesting for me as well...

Eb_Jon gravatar image Eb_Jon  ( 2016-05-31 07:30:44 -0500 )edit