Finding and fixing Ghostty's largest memory leak

Bug characteristics and impact

  • Leak involved “non-standard” scrollback pages and page reuse logic; some users hit it via Claude Code’s emoji-heavy output, others without Claude.
  • A few participants speculate settings like very small scrollback might increase incidence, but this is unclear.
  • Maintainer states the bug has existed ~3 years, affected relatively few users, and “largest” refers to bytes leaked per hit, not user reach.
  • Fix arrived only after a reliable reproduction appeared; an earlier GitHub comment with a similar-sounding diagnosis is judged likely incorrect.

Fix approach and alternatives

  • Current fix sometimes discards non-standard pages instead of reusing them even when reuse might be possible; this preserves existing PageList behavior.
  • Rationale: keep the mental model (“standard sizes are common”) and avoid changing both architecture and bug in one step.
  • Commenters suggest alternatives: tagging allocations, checking whether memory lies in the pool, or making sizes immutable across reallocs.
  • Some see the chosen fix as a pragmatic, minimal patch; others view it as a band-aid that leaves underlying “type confusion” risk.

Reproductions, issues, and project process

  • Multiple people emphasize that reliable reproductions are crucial for non-obvious leaks.
  • There’s debate about the project’s practice of using GitHub Discussions first and only creating Issues later; some call it “bizarre,” others defend it as triage.
  • Accusations of “gaslighting” users who reported leaks are countered by pointing out that asking for proof is effectively a request for repro steps.
  • HN guidelines (assume good faith, avoid cross-examination) are repeatedly cited in meta-discussion.

Performance, architecture, and language choices

  • Some are uneasy that a terminal needs a custom allocator and low-level mmap tricks; others argue high-performance terminals benefit from tight memory control, especially for large scrollback and smooth rendering.
  • Alternatives like circular buffers / VecDeque are proposed; maintainers elsewhere justify the linked-list pages as enabling future features like persisted or compressed scrollback.
  • Long subthread debates whether Rust (with enums/Drop, affine types) or a GC language (Go, C#) would have prevented this; counterpoints note:
    • Rust still needs unsafe for mmap-style APIs and permits leaks.
    • GC adds memory overhead and isn’t always acceptable on low-RAM systems.
    • Zig provides defer/errdefer and leak-detecting allocators, but those still require good repros.

User experience, adoption, and Claude Code

  • Several commenters praise the write-up’s accessibility and Ghostty’s polish, speed, and GPU-accelerated rendering.
  • Some surprise that the fix lands via nightlies and the normal release cycle rather than an emergency hotfix; others reply this is reasonable for a non-security, non-widespread bug.
  • Claude Code is seen as making CLI usage more attractive and as a stress test revealing Ghostty edge cases (memory leak, drag-and-drop images in tmux, copy-paste glitches).