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

delete TransformListener object in python to release computational resource

asked 2016-11-02 12:31:59 -0500

Mike Gao gravatar image

updated 2016-11-02 12:32:38 -0500

Hello! Recently I notice that, after I create a TransformListener object in a class in python, e.g.:

self.tf = TransformListener(),

the created tf object gets stuck in the memory, even I try deleting it in the "__del__(self)" method of the class with:

del self.tf

self.tf = None,

it does not work. The TransformListener object is used by a method of this class. The problem is that when I continue to create the object of this class (which is called by another class during operation), the TransformListener objects accumulate and occupy the computational resources. Thus my question is that how I can get rid of it to free the unnecessarily occupied resources? I appreciate any answers and suggestions in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-11-02 13:30:26 -0500

tfoote gravatar image

There may be something not cleaning up properly, but python does not necessarily clean up when del is called. http://effbot.org/pyfaq/why-doesnt-py...

Here are some more resources if you want to dig in deeper:

edit flag offensive delete link more
0

answered 2023-06-05 04:26:30 -0500

pajaz gravatar image

Here's what worked for me:

From: https://answers.ros.org/question/366778/how-to-delete-a-subcriberpublisher-in-rclpy/

I deleted the subscriber of tf2_ros.TransformListener:

self.tf_buffer = tf2_ros.Buffer()
self.tf_listener = tf2_ros.TransformListener(self.tf_buffer, self)

then delete with:

self.destroy_subscription(self.tf_listener.tf_sub)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-11-02 12:31:59 -0500

Seen: 286 times

Last updated: Nov 02 '16