diff options
author | zachir <zachir@librem.one> | 2023-11-05 17:13:59 -0600 |
---|---|---|
committer | zachir <zachir@librem.one> | 2023-11-05 17:13:59 -0600 |
commit | 6ca46530b2c59d21ec83cb86a2dfc07f1e00f073 (patch) | |
tree | a5a8e85acf3b4564ac4c2d76fe5404cd282b855a | |
parent | 1b4e212fb60e54b2fdbf0d4584af68b7959cc24c (diff) |
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.
-rw-r--r-- | cpu-widget/cpu-widget.lua | 12 | ||||
-rw-r--r-- | mpdarc-widget/mpdarc.lua | 12 | ||||
-rw-r--r-- | ram-widget/ram-widget.lua | 7 | ||||
-rw-r--r-- | volume-widget/volume.lua | 7 |
4 files changed, 38 insertions, 0 deletions
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) diff --git a/mpdarc-widget/mpdarc.lua b/mpdarc-widget/mpdarc.lua index a6a8e75..609efbf 100644 --- a/mpdarc-widget/mpdarc.lua +++ b/mpdarc-widget/mpdarc.lua @@ -87,13 +87,20 @@ mpdarc:connect_signal("button::press", function(_, _, _, button) elseif (button == 5) then awful.spawn(PREV_MPD_CMD, false) -- scroll down end + local reset_garbage_collector = 0 spawn.easy_async(GET_MPD_CMD, function(stdout, stderr, exitreason, exitcode) update_graphic(mpdarc, stdout, stderr, exitreason, exitcode) + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 10) then + collectgarbage() + reset_garbage_collector = 0 + end end) end) local notification local function show_MPD_status() + local reset_garbage_collector spawn.easy_async(GET_MPD_CMD, function(stdout, _, _, _) notification = naughty.notify { @@ -103,6 +110,11 @@ local function show_MPD_status() hover_timeout = 0.5, width = 600, } + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 10) then + collectgarbage() + reset_garbage_collector = 0 + end end) end diff --git a/ram-widget/ram-widget.lua b/ram-widget/ram-widget.lua index 867d28e..970c2d6 100644 --- a/ram-widget/ram-widget.lua +++ b/ram-widget/ram-widget.lua @@ -59,6 +59,8 @@ local function worker(user_args) return math.floor(value / (total+total_swap) * 100 + 0.5) .. '%' end + local reset_garbage_collector = 0 + watch('bash -c "LANGUAGE=en_US.UTF-8 free | grep -z Mem.*Swap.*"', timeout, function(widget, stdout) total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap = @@ -77,6 +79,11 @@ local function worker(user_args) {'buff_cache ' .. getPercentage(buff_cache), buff_cache} } end + reset_garbage_collector = reset_garbage_collector + 1 + if (reset_garbage_collector > 9) then + collectgarbage() + reset_garbage_collector = 0 + end end, ramgraph_widget ) diff --git a/volume-widget/volume.lua b/volume-widget/volume.lua index 4c44042..b689f6e 100644 --- a/volume-widget/volume.lua +++ b/volume-widget/volume.lua @@ -143,7 +143,9 @@ local function build_header_row(text) end local function rebuild_popup() + local reset_garbage_collector = 0 spawn.easy_async(LIST_DEVICES_CMD, function(stdout) + reset_garbage_collector = reset_garbage_collector + 1 local sinks, sources = utils.extract_sinks_and_sources(stdout) @@ -155,6 +157,11 @@ local function rebuild_popup() table.insert(rows, build_rows(sources, function() rebuild_popup() end, "source")) popup:setup(rows) + + if (reset_garbage_collector > 10) then + collectgarbage() + reset_garbage_collector = 0 + end end) end |