svghmi/svghmi.js
changeset 3650 9256c344c2da
parent 3648 ff42600fddd7
child 3653 d5ff60e906b0
--- a/svghmi/svghmi.js	Thu Oct 27 10:52:24 2022 +0200
+++ b/svghmi/svghmi.js	Fri Oct 28 09:44:33 2022 +0200
@@ -586,20 +586,21 @@
 switch_page(default_page);
 
 var reconnect_delay = 0;
-// var periodic_reconnect_timer;
+var periodic_reconnect_timer;
 
 // Once connection established
 function ws_onopen(evt) {
-    /* 
-    // to force reconnect every hour
-    if(periodic_reconnect_timer){
-        window.clearTimeout(periodic_reconnect_timer);
-    }
-    periodic_reconnect_timer = window.setTimeout(() => {
-        ws.close();
-        periodic_reconnect_timer = null;
-    }, 3600*1000);
-    */
+    // Work around memory leak with websocket on QtWebEngine
+    // reconnect every hour to force deallocate websocket garbage
+    if(window.navigator.userAgent.includes("QtWebEngine")){
+        if(periodic_reconnect_timer){
+            window.clearTimeout(periodic_reconnect_timer);
+        }
+        periodic_reconnect_timer = window.setTimeout(() => {
+            ws.close();
+            periodic_reconnect_timer = null;
+        }, 3600000);
+    }
 
     // forget subscriptions remotely
     send_reset();