Skip to content

Commit

Permalink
Merge pull request #964 from tue-robotics/fix-designator-memory-leak
Browse files Browse the repository at this point in the history
Use weak references to store active designators.
  • Loading branch information
MatthijsBurgh committed Dec 21, 2019
2 parents 7f53a0a + 0ecb61f commit dba15dc
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__author__ = 'loy'
import weakref
from deprecation_warnings import get_caller_info
import rospy

Expand All @@ -20,7 +21,7 @@ class Designator(object):
>>> assert(issubclass(d.resolve_type, str))
"""

instances = []
instances = weakref.WeakSet()

def __init__(self, initial_value=None, resolve_type=None, name=None):
"""
Expand All @@ -46,7 +47,7 @@ def __init__(self, initial_value=None, resolve_type=None, name=None):
else:
self._resolve_type = resolve_type

Designator.instances += [self]
Designator.instances.add(self)

def resolve(self):
"""Selects a new goal and sets it as the current value."""
Expand Down Expand Up @@ -205,12 +206,12 @@ class VariableWriter(object):
['a', 'b', 'c', 'd']
"""

instances = []
instances = weakref.WeakSet()

def __init__(self, variable_designator):
self.variable_designator = variable_designator
self.name = "writeable({})".format(self.variable_designator.name)
VariableWriter.instances += [self]
VariableWriter.instances.add(self)

def write(self, value):
"""
Expand Down

0 comments on commit dba15dc

Please sign in to comment.