{tag,task}list: Use a weak-valued table

The data table is used to map objects (clients/tags) to the buttons associated
with them. This is done so that we don't have to re-create the button objects
each time this lists are updated.

The problem was that this weak-keyed table was never cleared, because the value
had a strong reference to the key (via the button's signal):

btn:connect_signal("press", function () b:emit_signal("press", o) end)

"o" is the key in the table and btn is reachable from the value. This prevented
the garbage collection of the key. Using a weak-keyed and weak-valued table
fixes this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-09-16 17:28:50 +02:00
parent 2134a3c2e9
commit 9114ed1846
2 changed files with 2 additions and 2 deletions

View File

@ -57,7 +57,7 @@ function new(screen, label, buttons)
["right"] = 0},
["bg_resize"] = true
}
local data = setmetatable({}, { __mode = 'k' })
local data = setmetatable({}, { __mode = 'kv' })
local u = function (s)
if s == screen then
taglist_update(s, w, label, buttons, data, widgets)

View File

@ -53,7 +53,7 @@ function new(label, buttons)
bg_resize = true,
bg_align = "right"
}
local data = setmetatable({}, { __mode = 'k' })
local data = setmetatable({}, { __mode = 'kv' })
local u = function () tasklist_update(w, buttons, label, data, widgets) end
for s = 1, capi.screen.count() do
tag.attached_add_signal(s, "property::selected", u)