Replicate ghostty memleak as suggested here. This works only on Linux with bcc-tools package installated.
Modify your current ghostty config file to have a very small scrollback limit. This ensures you hit the pruning logic immediately.
# Most likely in ~/.config/ghostty/config file
scrollback-limit = 100
Below code forces ghostty to non-standard page allocation. Run this on ghostty terminal (that doesn't contain the fix)
import sys
import time
# A string heavy with emojis sequences to force non-standard page allocation
complex_line = "π¨βπ©βπ§βπ¦ " * 50
print(f"Starting leak generation... (Press Ctrl+C to stop)")
try:
i = 0
while True:
# Print the complex line with an index to keep lines unique
sys.stdout.write(f"{i} {complex_line}\n")
# Flush to ensure it hits the terminal immediately
sys.stdout.flush()
i += 1
time.sleep(0.001)
except KeyboardInterrupt:
print("\nStopped.")I am using memleak bpf program to detect the leak (preferably in another terminal).
Identify the pid of the ghostty process & pass it as an argument to memleak
sudo memleak-bpfcc -p <pid-of-ghostty> --combined-only
Attaching to pid 199300, Ctrl+C to quit.
[16:33:04] Top 10 stacks with outstanding allocations:
0 bytes in 0 allocations from stack
[unknown] [ghostty]
3408 bytes in 3 allocations from stack
[unknown] [ghostty]
...blah-blah....
2097152 bytes in 1 allocations from stack
[unknown] [ghostty]
1607151616 bytes in 170 allocations from stack ###around 1.6 GB leak
[unknown] [ghostty]This is an attempt to replicate on Linux & detect the same with eBPF based on discussion here.