From 6ca46530b2c59d21ec83cb86a2dfc07f1e00f073 Mon Sep 17 00:00:00 2001 From: zachir Date: Sun, 5 Nov 2023 17:13:59 -0600 Subject: Add reset_garbage_collector to sorta fix mem leaks I added in a variable to force clearing the garbage collector more often, so that the memory leaks involving awful.spawn.easy_async wouldn't cause massive performance issues over time. --- cpu-widget/cpu-widget.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cpu-widget') diff --git a/cpu-widget/cpu-widget.lua b/cpu-widget/cpu-widget.lua index 23b61f6..f1056e9 100644 --- a/cpu-widget/cpu-widget.lua +++ b/cpu-widget/cpu-widget.lua @@ -163,6 +163,7 @@ local function worker(user_args) -- This part runs constantly, also when the popup is closed. -- It updates the graph widget in the bar. local maincpu = {} + local reset_garbage_collector = 0 watch(CMD_slim, timeout, function(widget, stdout) local _, user, nice, system, idle, iowait, irq, softirq, steal, _, _ = @@ -178,12 +179,18 @@ local function worker(user_args) maincpu['idle_prev'] = idle widget:add_value(diff_usage) + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 5) then + collectgarbage() + reset_garbage_collector = 0 + end end, cpugraph_widget ) -- This part runs whenever the timer is fired. -- It therefore only runs when the popup is open. + local reset_garbage_collector = 0 local cpus = {} popup_timer:connect_signal('timeout', function() awful.spawn.easy_async(CMD, function(stdout, _, _, _) @@ -318,6 +325,11 @@ local function worker(user_args) margins = 8, widget = wibox.container.margin } + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 10) then + collectgarbage() + reset_garbage_collector = 0 + end end) end) -- cgit v1.2.3