From 5a0e9715f45b62cfe43e6873b8828f49ab73f710 Mon Sep 17 00:00:00 2001 From: Max Baryshnikov Date: Tue, 7 Feb 2017 22:31:06 +0300 Subject: Fixed couple of "leaks" when gc is disabled (#979) --- kafka/protocol/struct.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'kafka/protocol/struct.py') 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 -- cgit v1.2.1