From b84ade45f85f685ba96b829bf0e9afcb5b014079 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 9 May 2026 01:03:59 -0500 Subject: [PATCH] fix(meshchat, health_monitor): add garbage collection calls to cleanup resources during context teardown and health checks --- meshchatx/meshchat.py | 2 ++ meshchatx/src/backend/recovery/health_monitor.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/meshchatx/meshchat.py b/meshchatx/meshchat.py index 1367e5f..5a5ceac 100644 --- a/meshchatx/meshchat.py +++ b/meshchatx/meshchat.py @@ -850,6 +850,7 @@ class ReticulumMeshChat: if identity_hash in self.contexts: del self.contexts[identity_hash] self.current_context = None + gc.collect() def _teardown_all_contexts_for_reload(self): # Stop per-identity long-running services before tearing down contexts. @@ -879,6 +880,7 @@ class ReticulumMeshChat: self.contexts.clear() self.current_context = None self.running = False + gc.collect() async def _send_rns_reload_status( self, diff --git a/meshchatx/src/backend/recovery/health_monitor.py b/meshchatx/src/backend/recovery/health_monitor.py index 5a63100..93d2ca1 100644 --- a/meshchatx/src/backend/recovery/health_monitor.py +++ b/meshchatx/src/backend/recovery/health_monitor.py @@ -12,6 +12,7 @@ from in-memory deques kept by PersistentLogHandler and psutil. import asyncio import collections +import gc import json import logging import threading @@ -59,6 +60,7 @@ class HealthMonitor: self._check() except Exception as exc: _log.debug("HealthMonitor check error: %s", exc) + gc.collect() await asyncio.sleep(self.CHECK_INTERVAL) def _check(self):