SVGHMI: enable periodical reconnect when browser is QtWebengine, working around memory leak with websocket on Qt's embedded Chromium.
authorEdouard Tisserant
Fri, 28 Oct 2022 09:44:33 +0200
changeset 3650 9256c344c2da
parent 3649 61fa60130ad6
child 3651 e3a29c5b74c4
SVGHMI: enable periodical reconnect when browser is QtWebengine, working around memory leak with websocket on Qt's embedded Chromium.
svghmi/svghmi.js
--- 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();