From 6482965edc47962fd0fe8ba98cd110c31136a1cc Mon Sep 17 00:00:00 2001 From: sickprodigy Date: Wed, 5 Nov 2025 23:36:16 -0500 Subject: [PATCH] Add garbage collection to main loop for memory management --- main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.py b/main.py index 60b8cb8..b919023 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from machine import Pin import time import network import json +import gc # ADD THIS - for garbage collection # Initialize pins (LED light onboard) led = Pin("LED", Pin.OUT) @@ -249,6 +250,11 @@ while True: # Pass schedule_monitor so web interface can reload config when schedules change web_server.check_requests(sensors, ac_monitor, heater_monitor, schedule_monitor) + # ===== START: Garbage Collection ===== + # Free up unused memory to prevent fragmentation + gc.collect() + # ===== END: Garbage Collection ===== + # Small delay to prevent CPU overload (0.1 seconds = 10 loops per second) time.sleep(0.1) # ===== END: Main Loop ===== \ No newline at end of file