diff options
Diffstat (limited to 'kafka/protocol/struct.py')
-rw-r--r-- | kafka/protocol/struct.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/kafka/protocol/struct.py b/kafka/protocol/struct.py index a3d28d7..4c1afcb 100644 --- a/kafka/protocol/struct.py +++ b/kafka/protocol/struct.py @@ -5,6 +5,8 @@ from io import BytesIO from .abstract import AbstractType from .types import Schema +from ..util import WeakMethod + class Struct(AbstractType): SCHEMA = Schema() @@ -19,7 +21,9 @@ class Struct(AbstractType): self.__dict__.update(kwargs) # overloading encode() to support both class and instance - self.encode = self._encode_self + # Without WeakMethod() this creates circular ref, which + # causes instances to "leak" to garbage + self.encode = WeakMethod(self._encode_self) @classmethod def encode(cls, item): # pylint: disable=E0202 |