Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 475

Does rosbag write cause a memory leak?

$
0
0
I have the following code running on x86-64 Linux with ROS indigo: #include #include #include #include #include #define TWO_MiB (2*1024*1024) int main(int argc, char **argv) { std::string name("testwrite"); ros::init(argc, argv, name, 0); struct sysinfo info; ros::Time time = ros::Time::now(); ros::Rate loop(1); // 1 Hz while(ros::ok()) { std_msgs::String str; rosbag::Bag *bag = new rosbag::Bag(); // Using bagmode::Write mode does not cause a memory leak. // but it also does not write continuously to a file, as you would expect. bag->open("test.bag", rosbag::bagmode::Append); sysinfo(&info); ROS_INFO("TR0. Mem: Free:%.1f MB\n", info.freeram / (float) 1e6); void *mem = malloc(TWO_MiB); if (!mem) goto loop_free; memset(mem, 'a', TWO_MiB); str.data = (char *) mem; // Remove the following line and no memory is leaked. bag->write("strings", time, str); sysinfo(&info); ROS_INFO("TR1. Mem: Free:%.1f MB\n", info.freeram / (float) 1e6); // Ensure the memory used by the bag is **really** free bag->close(); delete bag; loop_free: free(mem); sysinfo(&info); ROS_INFO("TR2. Mem: Free:%.1f MB\n", info.freeram / (float) 1e6); loop.sleep(); } return 0; } And the output is as follows: [ INFO] [1440540265.784606302]: TR0. Mem: Free:3250.6 MB [ INFO] [1440540265.811953308]: TR1. Mem: Free:3229.3 MB [ INFO] [1440540265.814442553]: TR2. Mem: Free:3241.2 MB [ INFO] [1440540266.784350396]: TR0. Mem: Free:3241.3 MB [ INFO] [1440540266.808669181]: TR1. Mem: Free:3225.1 MB [ INFO] [1440540266.811110143]: TR2. Mem: Free:3236.9 MB [ INFO] [1440540267.784398301]: TR0. Mem: Free:3237.0 MB [ INFO] [1440540267.808999283]: TR1. Mem: Free:3220.7 MB [ INFO] [1440540267.811474048]: TR2. Mem: Free:3232.6 MB [ INFO] [1440540268.784463342]: TR0. Mem: Free:3232.7 MB [ INFO] [1440540268.808201640]: TR1. Mem: Free:3216.5 MB [ INFO] [1440540268.810761252]: TR2. Mem: Free:3228.3 MB [ INFO] [1440540269.784520258]: TR0. Mem: Free:3228.4 MB [ INFO] [1440540269.809175512]: TR1. Mem: Free:3212.2 MB [ INFO] [1440540269.811680539]: TR2. Mem: Free:3224.0 MB [ INFO] [1440540270.789515610]: TR0. Mem: Free:3224.1 MB [ INFO] [1440540270.814318890]: TR1. Mem: Free:3207.8 MB [ INFO] [1440540270.816899544]: TR2. Mem: Free:3219.8 MB [ INFO] [1440540271.784680288]: TR0. Mem: Free:3219.7 MB [ INFO] [1440540271.809407003]: TR1. Mem: Free:3203.2 MB [ INFO] [1440540271.811989272]: TR2. Mem: Free:3215.2 MB If I comment out bag.write the memory on my system stays stable. Am I using rosbag incorrectly or is the call to rosbag::Write leaking memory?

Viewing all articles
Browse latest Browse all 475

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>