'Why does emacs intermittantly not use the alternate screen?

I use emacs with the -nw flag so that it runs in the terminal. I don't run it inside screen or tmux or anything like that, just a plain terminal. Often when I exit emacs I return to a view of my terminal that shows the emacs command I typed but no longer shows the file I was editing or the emacs menu bar or anything like that. From this question I take it that this behavior is because emacs uses a so called "alternate screen" in my terminal. This is the behavior I want.

Maybe 30% of the time when I exit emacs the file I was editing and the menu bar and such are still on the screen. Why does this happen and how can I prevent it?

Based on this answer I tried the hacky solution of aliasing emacs to "tput smcup; emacs -nw". That seemed to reduce the frequency of the problem down to maybe 5 or 10%, but it didn't fix it and I'm sure it's not the "right" thing to do anyway. Any help would be appreciated.



Solution 1:[1]

IIUC this has been resolved for Emacs 29. Refer to the NEWS.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 phils