Add garbage collection to main loop for memory management

This commit is contained in:
2025-11-05 23:36:16 -05:00
parent 5d162f3971
commit 6482965edc

View File

@@ -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 =====