We just completed rewriting the Ghostty GTK application fully embracing the GObject type system from Zig and also verifying with Valgrind every step of the way. The result is a more feature rich, stable, and maintainable Ghostty on Linux and BSD. There are multiple interesting, technical topics from this process, but I want to focus in on two (1) interfacing with the GObject type system from Zig and (2) verifying a GTK application with Valgrind and reflecting on the memory issues Valgrind found in a Zig codebase. Background First, some quick background. Ghostty is cross-platform (macOS, Linux, FreeBSD) terminal emulator. Ghostty sets itself apart from other cross-platform terminal emulators by using a platform-native application or GUI framework for each platform1. On macOS, Ghostty is a multi-thousand line Swift application built with Xcode. On Linux and BSD, Ghostty is a multi-thousand line GTK application leveraging direct integrations with X11, Wayland, etc. Tying it all together, there is a very large shared core written in Zig that exports a C ABI compatible API. For full motivation on why Ghostty was the way it was before and why we decided to rewrite the GTK application now, see the original "gtk-ng" PR. I'm going to keep this post focused on the takeaways rather than the motivation. GObject Type System and Zig Whatever your feelings are about OOP and memory management, the reality is that if you choose GTK, you're forced into interfacing in some way with the GObject type system. You can't avoid it. Well you can avoid it and we did avoid it. And it leads to a mess trying to tie the lifetimes of your non-reference-counted objects to the reference counted ones. There was an entire class of bug that kept popping up in the Ghostty GTK application that could basically be summed up as: the Zig memory or the GTK memory has been freed, but not both. Besides the correctness issues, avoiding the object system also forced us away from using GTK-native features such as ...
First seen: 2025-08-14 22:18
Last seen: 2025-08-15 19:22