Bladeren bron

fix memory leak issue

tuanchris 3 maanden geleden
bovenliggende
commit
e3c6071923
2 gewijzigde bestanden met toevoegingen van 19 en 1 verwijderingen
  1. 10 0
      static/js/base.js
  2. 9 1
      static/js/led-control.js

+ 10 - 0
static/js/base.js

@@ -884,6 +884,16 @@ function initializeWebSocket() {
     connectWebSocket();
 }
 
+// Clean up WebSocket when page unloads to prevent memory leaks
+window.addEventListener('beforeunload', () => {
+    if (ws) {
+        // Disable reconnection before closing
+        ws.onclose = null;
+        ws.close();
+        ws = null;
+    }
+});
+
 // Add resize handler for responsive canvas with debouncing
 let resizeTimeout;
 window.addEventListener('resize', () => {

+ 9 - 1
static/js/led-control.js

@@ -310,7 +310,15 @@ async function initializeDWLedsControls() {
     });
 
     // Update remaining time periodically
-    setInterval(updateIdleTimeoutRemaining, 60000); // Update every minute
+    let idleTimeoutInterval = setInterval(updateIdleTimeoutRemaining, 60000); // Update every minute
+
+    // Clean up interval when page unloads
+    window.addEventListener('beforeunload', () => {
+        if (idleTimeoutInterval) {
+            clearInterval(idleTimeoutInterval);
+            idleTimeoutInterval = null;
+        }
+    });
 
     // Initialize Coloris color picker for effect colors
     initializeColoris();