szn

Bug 360 — Scrollback cap bounds logical state, not memory

360. Evicted history lines are never actually returned to the OS

File: src/grid.zig:245-257 Severity: HIGH Status: Fixed

Problem

scrollUp correctly caps live history at history_limit, but every eviction calls line.deinit(self.allocator) where self.allocator is the session arena — ArenaAllocator.free is a no-op for any non-most-recent allocation. The session’s memory footprint grows in proportion to all terminal output ever produced, not to the configured scrollback.

Root Cause

Grid (and its lines) allocate from the session arena by design; there is no mechanism to release individual lines.

Fix (proposed)

Give Grid.history a dedicated resettable arena (reset on compaction when history_start wraps) or a general-purpose allocator with true per-line frees. Alternative: compact + arena.reset(.retain_capacity) once live count drops below half the high-water mark. Related: bug #371 (reflow bypasses the limit entirely) and #359 (clock-mode churn).