Top
Best
New

Posted by thorel 1/10/2026

Finding and fixing Ghostty's largest memory leak(mitchellh.com)
632 points | 138 comments
quantummagic 1/10/2026|
This is great news! Well done to everyone who helped sort it out. It was a problem noted by users in a thread here just last week, https://news.ycombinator.com/item?id=46460319

While Claude Code might have been the reason this bug became triggered by more people, there are some of us who were hitting it without ever having used Claude Code at all. Maybe the assumption about what makes a page non-standard, isn't as black-and-white as presumed. And I wonder if the leak would have been triggered more often for people who use scrollback-limit = 0, or something very small.

Probably not a huge deal, but it does seem the fix will needlessly delete and recreate non-standard pages in the case where the new page needs to be non-standard, and the oldest one (that needs to be pruned) already is non-standard and could be reused.

mitchellh 1/10/2026||
> Probably not a huge deal, but it does seem the fix will needlessly delete and recreate non-standard pages in the case where the new page needs to be non-standard, and the oldest one (that needs to be pruned) already is non-standard and could be reused.

This is addressed in the blog post.

It is how the PageList has always worked, and also how it worked before with the bug, because during capacity adjustment we would see the wrong size. This shouldn't change any perceived performance.

And as I note in the blog post, there are alternative approaches such as the one you suggested, but we don't have enough empirical data to support changing our viewpoint on that whereas our current viewpoint (standard sizes are common) is well supported by known benchmarks. I'm open to changing my mind here, but I didn't want to change worldviews AND fix the leak in the same go.

fartfeatures 1/11/2026|||
How come this isn't released as a hotfix / out of band patch but will follow the standard release cycle in March?
fragmede 1/10/2026|||
Of all the things to be impressed by you about, your patience is commendable. I'd be losing my shit if someone couldn't be bothered to read what I wrote and just spout off about something I'd addressed in my writing, but I suppose that's why your bank account has two commas and a bunch more. Thank you for everything. Can we go flying sometime?
Aurornis 1/11/2026|||
> I'd be losing my shit if someone couldn't be bothered to read what I wrote and just spout off about something I'd addressed in my writing

In my experience that’s a universal feature of comment sections everywhere, and HN is not an exception. This is very common in HN comments which is why it’s important to always read the article, not just the comments.

ATMLOTTOBEER 1/11/2026|||
[flagged]
fragmede 1/11/2026||
Hell yeah! You don't got any heros? No body you look up to or respect? Not even a little bit?
commandersaki 1/11/2026|||
> Well done to everyone who helped sort it out. It was a problem noted by users in a thread here just last week

I'm feeling a bit lucky I was able to sneak in an issue during the beta phase, but it was a real reproducible one that led to a segfault.

macote 1/10/2026|||
The thread about memory leak is here: https://news.ycombinator.com/item?id=46461061
Maxious 1/11/2026||
And the same diagnosis in the blog post was reported by a user in discussions a month ago but ignored https://github.com/ghostty-org/ghostty/discussions/9786#disc...
julien_p 1/11/2026||
That doesn't sound like the actual issue, or am I not understanding it correctly?
dkdcio 1/11/2026||
I think you’re correct. the reproduction isn’t very precise and the solution doesn’t seem right (I’m not seeing anything about the non-standard pages not being freed). I’d guess this was ignored because it was wrong…
larodi 1/11/2026||
As a side note - Claude Code is making the CLI attractive in a renewed fashion - more than anything else did it last 20years.
jrpelkonen 1/10/2026||
Great write-up. And, thanks mitchellh for Ghostty, I switched to it last year, and have not regretted it.

However, I am a somewhat surprised that the fix is reserved for a feature release in a couple of months. I would have expected this to be included in a bug fix release.

msephton 1/11/2026|
It's already released in the latest nightly build.
DrammBA 1/11/2026||
Are the nightly releases the expected way to get timely bugfixes?
amazingman 1/11/2026|||
That is how software releases generally work. AFAICT this is not a bug with broad impact or security implications.
fartfeatures 1/11/2026||
I guess thats arguable, a memory leak can make a system unpleasant to use although I accept it can be solved by repeatedly restarting the offending app.
msephton 1/15/2026|||
Yes, if you want fixes as soon as they're committed, rather than waiting for a more regular release that might be tested and more stable.
reactordev 1/11/2026||
The moment you started talking about pages, I was like: “Ok, obviously memory pooled” and yup, it is. Then I said “obviously ring buffered” and yeah, essentially your scroll back reuse. Then I knew exactly where the bug was before getting to that part, not freeing the pages memory properly and sure enough - bingo! With some great looking diagrams of memory space alignment.

Kudos, that was a good read. Just remember that every time you do something novel, there’s potential for leaks :D

neobrain 1/10/2026||
Funny timing, I moved to Ghostty this week and just today I ran into OOM crashes in Ghostty while developing a terminal UI app. Coincidentally this TUI has a tab bar that looks like this, where UTF8 icons are used for recognizability and activity indicators (using © and € as placeholders here):

    1|Flakes ©    2|Installed ©    3|Store © €    4|Security © €
   ──────────────────────────────────────────────────────────────
This works fine normally, but resizing the terminal would quickly trigger the crash - easy to avoid but still annoying!

I was already preparing myself to file a bug report with the easy repro, but this sounds suspiciously close to what the blog post is describing. Fingers crossed :)

(EDIT: HN filters unicode, booo :( )

smoyer 1/11/2026|
Why would I move to GhosTTY versus the terminal emulator that comes with my OS as it's not clear to me from the documentation?
neobrain 1/11/2026|||
I don't think I can do a better overview than https://ghostty.org/docs/about . It's not world-changing but simply a very polished, well-executed terminal.

GPU rendering virtually eliminates typing latency. Most terminals that have it don't support native content like tabs, but Ghostty gets minimal latency without having to compromise on essentials since it uses native toolkits under the hood.

The modern TTY has lots of protocol extensions that allow your CLI tools to do things like display high-resolution images. There's tons of good-quality color themes out-of-the-box (with a built-in browser for preview).

Configuration is highly customizable but the defaults are good enough that you barely need it.

smoyer 1/12/2026||
I wish a couple of those paragraphs were on the home page!
geon 1/14/2026|||
I moved because Ghostty feels just like the native terminal but allows me to set the color scheme. I have it set to match the vscode Monokai theme.

No, macos Terminal will not let you use whatever colors you like. It will helpfully adjust the colors you select to increase contrast. And it can't be disabled. It bugged me for years.

hotpotat 1/10/2026||
@mitchellh what did you use for the memory visualizations? Looks nice, and the website plays well with mobile. Whats the stack?
mitchellh 1/10/2026|
Static HTML/CSS generated by Opus 4.5.

I like using AI for visualizations because it is one-time use throwaway code, so the quality doesn't matter at all (above not being TOTALLY stupid), it doesn't need to be maintained. I review the end result carefully for correctness because it's on a topic I'm an expert of.

I produce non-reusable diagrams namespaced by blog post (so they're never used by any other post). I just sanity check that the implementation isn't like... mining bitcoin or leaking secrets (my personal site has no secrets to build) or something. After that, I don't care at all about that quality.

The information is conveys is the critical part, and diagrams like this make it so much more consumable for people.

63 1/10/2026|||
That's really cool. I was looking at them and thinking "I could probably make these with vanilla html/css but it'd be pretty tedious." Perfect use case for AI. I need to work on developing a reflex for it.
mjn 1/10/2026||
I've also started doing this, and it's surprisingly enjoyable to both do and even to read. The end result is often more readable to me than using a 3rd-party JS visualization library, because I only need to know standard HTML/CSS concepts to understand what's going on. And a side benefit is smaller pages with less bitrot due to being able to skip the dependencies.
hotpotat 1/10/2026|||
That’s reasonable, thanks!
jhhh 1/11/2026||
This feels like a case of guessing at something you could know. There are two types of allocations that each have a size and free method. The free method is polymorphic over the allocations type. Instead of using a tag to know absolutely which type an object it is you guess based on some other factor, in this case a size invariant which was violated. It also doesn't seem like this invariant was ever codified otherwise the first time a large alloc was modified to a standard size it would've blown up. It's worth asking yourself if your distinguishing factor is the best you can use or perhaps there is a better test. Maybe in this case a tag would've been too expensive.
stephc_int13 1/11/2026||
I've been following the development of Ghostty for a while and while I have the feeling that there is a bit of over-engineering in this project, I find this kind of bug post mortem to be extremely valuable for anyone in love with the craft.
trevorhinesley 1/11/2026|
Over-engineered in what way?
nesarkvechnep 1/11/2026|||
It’s just a feeling, man.
cbmuser 1/11/2026|||
Having to introduce a new language stack to distributioms just to be able to build a terminal emulator is what I would consider over-engineering.
surajrmal 1/11/2026|||
So anything that uses a less popular language is considered over engineering? Distros support lots of different languages already and there are likely other packages built with zig already.
weebull 1/11/2026|||
A 50-ish MB build time dependency that doesn't need any special privileges or installation to run? That's over engineering? A binary release of just CMake is bigger than all of Zig.
bryancoxwell 1/10/2026||
Super accessible write up as someone unfamiliar with Ghostty and terminal emulators in general. Thanks!
kepano 1/10/2026||
Reliable reproductions are so valuable.
drob518 1/10/2026|
Why not just use a circular buffer for the scroll back? Why use blocks at all if you’re just going to recycle them anyway? That said, great write-up.
mitchellh 1/10/2026|
It started that way, and that's a common way to do this. One of the reasons is to avoid large pre-allocations OR large copies. A few other notes over on lobsters: https://lobste.rs/s/vlzg2m/finding_fixing_ghostty_s_largest_...
drob518 1/11/2026||
Cool, thanks for the link.
More comments...