If you close a terminal emulator in such a way that it kills the shell
without letting the shell write history to disk, then the history will
not be saved.
If you want history to be saved, you should exit from the *shell*
(e.g. by pressing Ctrl-D), rather than closing the terminal and
counting
on that to terminate the shell in a way that will preserve history.
If you *don't* want history to be saved, there are many ways to make
that (not) happen, depending on your terminal emulator and so on.
You'll
need to experiment, though, to see exactly what happens when you do
whatever it is you do.
Whenever I need to reboot my computer (kernel update or the like), I
decide which shells I want to retain history from, and I exit from
those
cleanly (^D). I leave the others running, and exit from FVWM, which
kills them in a way that causes their history not to be written.
If you want a particular shell window's history to be AGGRESSIVELY
written to disk every time you run a command, you can arrange for that
as well. See <https://mywiki.wooledge.org/BashFAQ/088> for example.