ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

roscpp memory usage

asked 2014-11-03 13:21:14 -0500

t.pimentel gravatar image

updated 2014-11-04 12:34:27 -0500

I used Valgrind to check memory usage in a program I'm creating and found out that the problem is mostly in rosccp.

==21986== 5,380,160 bytes in 3,440 blocks are definitely lost in loss record 161 of 161
==21986==    at 0x4C2CC70: calloc (in /usr/lib/valgrind/
==21986==    by 0x68A9637: getifaddrs_internal (ifaddrs.c:402)
==21986==    by 0x68AA19F: getifaddrs (ifaddrs.c:825)
==21986==    by 0x5328D15: ros::Transport::Transport() (in /opt/ros/indigo/lib/
==21986==    by 0x53342BF: ros::TransportTCP::TransportTCP(ros::PollSet*, int) (in /opt/ros/indigo/lib/
==21986==    by 0x5334716: ros::TransportTCP::accept() (in /opt/ros/indigo/lib/
==21986==    by 0x5335B52: ros::TransportTCP::socketUpdate(int) (in /opt/ros/indigo/lib/
==21986==    by 0x5364E4D: ros::PollSet::update(int) (in /opt/ros/indigo/lib/
==21986==    by 0x53022A7: ros::PollManager::threadFunc() (in /opt/ros/indigo/lib/
==21986==    by 0x739AA49: ??? (in /usr/lib/x86_64-linux-gnu/
==21986==    by 0x75AD181: start_thread (pthread_create.c:312)
==21986==    by 0x688FFBC: clone (clone.S:111)
==21986== LEAK SUMMARY:
==21986==    definitely lost: 5,422,612 bytes in 3,469 blocks
==21986==    indirectly lost: 207,979 bytes in 4,227 blocks
==21986==      possibly lost: 2,467 bytes in 18 blocks
==21986==    still reachable: 3,376 bytes in 39 blocks
==21986==         suppressed: 0 bytes in 0 blocks
==21986== Reachable blocks (those to which a pointer was found) are not shown.
==21986== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==21986== For counts of detected and suppressed errors, rerun with: -v
==21986== ERROR SUMMARY: 30 errors from 30 contexts (suppressed: 0 from 0)

Is there anyway around it? This test was made with the program running for only 5 minutes, after two hours with my program running it slows down considerably because of this memory usage.

==== EDIT ====

I'm adding here an example code that shows this behavior in my laptop:

#include "ros/ros.h"

#include "custom_pkg_msgs/CustomAction.h"
#include "custom_pkg_msgs/CustomSrv.h"

#include <mcheck.h>

int main(int argc, char **argv)
    // start ros
    ros::init(argc, argv, "test_node");
    ros::NodeHandle n;
    ros::Rate loop_rate(1);

    srand (time(NULL)); // start random fucntions

    ros::Publisher chatter_pub = n.advertise<custom_pkg_msgs::CustomAction>("/random_topic", 1000);

    // client to start game service and server for end game service
    ros::ServiceClient start_game_client = n.serviceClient<custom_pkg_msgs::CustomSrv>("/random_service");
    ros::service::waitForService("/random_service", -1);

    // spin to answer services

    // shutdown ros node

And in the terminal I run: valgrind --leak-check=full --trace-children=yes rosrun custom_package test_node

I'm running valgrind-3.10.0.SVN on a Ubuntu 14.04, 64bits and with ROS indigo.

edit retag flag offensive close merge delete


It would probably help if you could post the code that you are running through Valgrind.

gvdhoorn gravatar image gvdhoorn  ( 2014-11-03 14:06:32 -0500 )edit

I edited my question with an example code.

t.pimentel gravatar image t.pimentel  ( 2014-11-03 14:44:50 -0500 )edit

As in this question, Valgrind versions can differ greatly in their sophistication when it comes to detecting leaks. Could you add some version information to your OP? ROS, OS, valgrind?

gvdhoorn gravatar image gvdhoorn  ( 2014-11-04 08:48:19 -0500 )edit

I'm using valgrind-3.10.0.SVN on a Ubuntu 14.04, 64bits and ROS indigo.

A task manager, htop, also exposes this problem. The memory used by the ROS program increases indefinitely.

t.pimentel gravatar image t.pimentel  ( 2014-11-04 12:33:46 -0500 )edit

Could you describe what other nodes you have running? I'm not able to reproduce the memory leak by just running the code posted here - do you have subscribers on the chatter_pub topic?

jbinney gravatar image jbinney  ( 2014-11-04 13:53:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-02-26 17:59:03 -0500

tfoote gravatar image

This looks like it's ticketed here:

edit flag offensive delete link more

Question Tools



Asked: 2014-11-03 13:21:14 -0500

Seen: 1,583 times

Last updated: Feb 26 '15