From 395b7fb7ec625258886284d7bc33b666214cf2de Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 26 Feb 2026 09:17:31 +0000 Subject: [PATCH] Fix polling interval memory leak - store all interval IDs Co-Authored-By: Claude Opus 4.6 --- static/script.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/static/script.js b/static/script.js index 265ba76c..02fac38f 100644 --- a/static/script.js +++ b/static/script.js @@ -499,7 +499,7 @@ let imgW = 0, imgH = 0; let scale = 1, offX = 0, offY = 0, minScale = 1; let dragging = false, sx = 0, sy = 0; let selected = ""; -let pollID = null; +const pollIntervals = []; /* ---------- utility functions ----------------------------------- */ const hue = name => { @@ -1449,15 +1449,21 @@ function handleServerStatusUpdate(msg) { } function startPolling() { - if (pollID !== null) return; + // Clear any existing intervals first (prevents leak on re-init) + pollIntervals.forEach(id => clearInterval(id)); + pollIntervals.length = 0; + + // Initial fetches pollLive(); - pollTotalRares(); // Initial fetch - pollTotalKills(); // Initial fetch - pollServerHealth(); // Initial server health check - pollID = setInterval(pollLive, POLL_MS); - setInterval(pollTotalRares, POLL_RARES_MS); - setInterval(pollTotalKills, POLL_KILLS_MS); - setInterval(pollServerHealth, POLL_HEALTH_MS); + pollTotalRares(); + pollTotalKills(); + pollServerHealth(); + + // Set up recurring polls + pollIntervals.push(setInterval(pollLive, POLL_MS)); + pollIntervals.push(setInterval(pollTotalRares, POLL_RARES_MS)); + pollIntervals.push(setInterval(pollTotalKills, POLL_KILLS_MS)); + pollIntervals.push(setInterval(pollServerHealth, POLL_HEALTH_MS)); } img.onload = () => {