Closed
Description
It looks like there is a memory leak in the ParserBuffer, caused by the _writer generator. This simplification shows the issue:
import gc
gc.collect() # => make sure we start clean
class ParserBuffer:
# defined __slots__ in this simplification so we produce the same garbage result
__slots__ = ('_writer', )
def __init__(self):
self._writer = self._feed_data()
next(self._writer)
def _feed_data(self):
while True:
chunk = yield
parserBuffer = ParserBuffer()
parserBuffer = None
gc.set_debug(gc.DEBUG_LEAK)
print(gc.collect()) # => Collects 3 objectsThe generator is not closed and holds a reference to self and therefore creates a reference cycle. Is it really necessary to use a generator? (Or can we somehow make sure the generator is closed using self._writer.close() ?)