Free up cells memory on resize

This commit is contained in:
Andrew de los Reyes
2025-04-20 09:44:39 -07:00
parent b469f6259d
commit a9ac482647

View File

@ -1784,6 +1784,15 @@ pub fn rebuildCells(
}
}
// Free up memory, generally in case where surface has shrunk.
// If more than half of the capacity is unused, remove all unused capacity.
if (self.cells.items.len * 2 < self.cells.capacity) {
self.cells.shrinkAndFree(self.alloc, self.cells.items.len);
}
if (self.cells_bg.items.len * 2 < self.cells_bg.capacity) {
self.cells_bg.shrinkAndFree(self.alloc, self.cells_bg.items.len);
}
// Some debug mode safety checks
if (std.debug.runtime_safety) {
for (self.cells_bg.items) |cell| assert(cell.mode == .bg);