From d3462ee56bf689b40738cdf5e9a3b378e9996d4e Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 23 May 2025 13:50:38 +0800 Subject: internal: fix memory leaks --- services/Hyprland.qml | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'services/Hyprland.qml') diff --git a/services/Hyprland.qml b/services/Hyprland.qml index 515441e..7a2538e 100644 --- a/services/Hyprland.qml +++ b/services/Hyprland.qml @@ -60,12 +60,9 @@ Singleton { const clients = JSON.parse(data); const rClients = root.clients; - const len = rClients.length; - for (let i = 0; i < len; i++) { - const client = rClients[i]; - if (!clients.find(c => c.address === client?.address)) - rClients.splice(i, 1); - } + const destroyed = rClients.filter(rc => !clients.find(c => c.address === rc.address)); + for (const client of destroyed) + rClients.splice(rClients.indexOf(client), 1).forEach(c => c.destroy()); for (const client of clients) { const match = rClients.find(c => c.address === client.address); @@ -88,9 +85,18 @@ Singleton { splitMarker: "" onRead: data => { const client = JSON.parse(data); - root.activeClient = client.address ? clientComp.createObject(root, { - lastIpcObject: client - }) : null; + const rClient = root.activeClient; + if (client.address) { + if (rClient) + rClient.lastIpcObject = client; + else + root.activeClient = clientComp.createObject(root, { + lastIpcObject: client + }); + } else { + rClient.destroy(); + root.activeClient = null; + } } } } -- cgit v1.2.3-freya