Skip to content

Commit

Permalink
console.lua: fix select memory leak
Browse files Browse the repository at this point in the history
The overlay to calculate the max item width was never removed, so a new
one was added on each select call, adding 5-10 MBs of memory usage
everytime.

Also remove the overlay to calculate the width to height ratio for
completions while at it, though I can't measure any memory difference
with this one.
  • Loading branch information
guidocella committed Feb 27, 2025
1 parent f2694f5 commit cd672a6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ local function measure_bounds(ass_text)
text_osd.res_x, text_osd.res_y = osd_width, osd_height
text_osd.data = ass_text
local res = text_osd:update()
text_osd:remove()
return res.x0, res.y0, res.x1, res.y1
end

Expand Down Expand Up @@ -340,6 +341,7 @@ local function calculate_max_item_width()
(font and '\\fn' .. font or '') .. '\\q2}' ..
ass_escape(longest_item)
local result = width_overlay:update()
width_overlay:remove()
max_item_width = math.min(result.x1 - result.x0,
osd_w - get_margin_x() * 2 - opts.padding * 2)
end
Expand Down

0 comments on commit cd672a6

Please sign in to comment.