From a25f6168e1d21c4dc2da1466fe4b83a7f5b19b64 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Sat, 2 Nov 2024 23:17:05 +0000 Subject: [PATCH] Attempt to aid memory issues --- runtimepy/net/server/app/env/tab/message.py | 4 +--- runtimepy/net/server/websocket/state.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/runtimepy/net/server/app/env/tab/message.py b/runtimepy/net/server/app/env/tab/message.py index 755a7433..331d7889 100644 --- a/runtimepy/net/server/app/env/tab/message.py +++ b/runtimepy/net/server/app/env/tab/message.py @@ -69,9 +69,7 @@ def handle_shown_state( for name in env.names: self._setup_callback(name, state) else: - # Remove callbacks for primitives. - for name, val in state.callbacks.items(): - state.primitives[name].remove_callback(val) + state.clear_loggers() # Save current UI state. state.latest_ui_values.update(latest) diff --git a/runtimepy/net/server/websocket/state.py b/runtimepy/net/server/websocket/state.py index 4bc9f078..59d3efdb 100644 --- a/runtimepy/net/server/websocket/state.py +++ b/runtimepy/net/server/websocket/state.py @@ -56,10 +56,21 @@ def frame(self, time: float) -> JsonMessage: def clear_loggers(self) -> None: """Clear all logging handlers.""" + # Remove handlers. for logger in self._loggers: logger.removeHandler(self.tab_logger) + self._loggers.clear() + self.tab_logger.drain_str() - self._loggers = [] + + # Remove callbacks for primitives. + for name, val in self.callbacks.items(): + self.primitives[name].remove_callback(val) + self.callbacks.clear() + self.primitives.clear() + + # Clear points. + self.points.clear() def add_logger(self, logger: logging.Logger) -> None: """Add a logger."""