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

rospy Subscriber object not getting destroyed?

asked 2012-11-16 18:25:05 -0600

Bill Smart gravatar image

updated 2012-11-17 12:10:18 -0600

This just came up in an assignment that I'm grading, and I can't figure out why it works. In the constructor of a class, there is:

self.sub = rospy.Subscriber('/odom', Odometry, self.seek_goal)

followed immediately by

self.sub = rospy.Subscriber('/base_scan', LaserScan, self.laser_agg)

My understanding is that, when self.sub is reassigned, the original Subscriber should go out of scope, get destroyed, and get garbage-collected. However, both callbacks seem to run happily for the duration of the node's existence.

Any Python gurus out there with any insight? I could guess about the object not getting reaped, but it should still go out of scope (and get destroyed), right?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-11-18 09:10:25 -0600

Lorenz gravatar image

After looking at rospy's source code, it looks like no __del__ method is implemented for subscribers. That means, topics are just not cleaned up when a subscriber object is destroyed. The user needs to manually unregister topics.

I'm not sure if this was intended behavior but I would consider filing an enhancement ticket.

edit flag offensive delete link more


I recently noticed a similar issue with rospy service advertisements.

joq gravatar image joq  ( 2012-11-24 03:26:57 -0600 )edit

Question Tools

1 follower


Asked: 2012-11-16 18:25:05 -0600

Seen: 681 times

Last updated: Nov 18 '12