History function in SSH

It does. But the question is how? What happen if you close terminal window? In this case for me last history is not saved. It is saved only when issuing exit command to log out from the session.