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)