Skip to content

Commit

Permalink
Explicitly free memory from SSE events
Browse files Browse the repository at this point in the history
  • Loading branch information
fajpunk committed Jan 21, 2025
1 parent 1d7a5eb commit e6fdee5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/timessquare/services/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ async def iterator() -> AsyncIterator[bytes]:
)
yield payload.to_sse().encode()

# If we don't explicitly tell it to, the garbage collector
# will not free the memory from these payloads, memory will
# leak from any tab streaming events from this iterator.
del payload

await asyncio.sleep(1)
except asyncio.CancelledError:
self._logger.debug("HTML events disconnected from client")
Expand Down

0 comments on commit e6fdee5

Please sign in to comment.