From ef57e1e56aa13af704cb18b4cb1074a8709ab759 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 24 Oct 2022 16:09:08 -0700 Subject: [PATCH] free memory in cells LRU --- src/renderer/OpenGL.zig | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 40ad1e036..d0932d8f0 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -315,7 +315,13 @@ pub fn deinit(self: *OpenGL) void { self.ebo.destroy(); self.vao.destroy(); self.program.destroy(); - self.cells_lru.deinit(self.alloc); + + { + // Our LRU values are array lists so we need to deallocate those first + while (self.cells_lru.queue.pop()) |node| node.data.value.deinit(self.alloc); + self.cells_lru.deinit(self.alloc); + } + self.cells.deinit(self.alloc); self.* = undefined; } @@ -537,7 +543,6 @@ pub fn rebuildCells(self: *OpenGL, term: *Terminal) !void { continue; } - // Get the starting index for our row so we can cache any new GPU cells. const start = self.cells.items.len; @@ -557,7 +562,15 @@ pub fn rebuildCells(self: *OpenGL, term: *Terminal) !void { } // Initialize our list - if (!gop.found_existing) gop.value_ptr.* = .{}; + if (!gop.found_existing) { + gop.value_ptr.* = .{}; + + // If we evicted another value in our LRU for this one, free it + if (gop.evicted) |kv| { + var list = kv.value; + list.deinit(self.alloc); + } + } var row_cells = gop.value_ptr; // Get our new length and cache the cells.