The server has no way of knowing if the visitor closed the browser window. All it can discover is if a session has not seen any activity for some time.
What you have to do is keep an eye on all your current sessions yourself somehow, and periodically delete those sessions that haven't seen any activity in some time, and do whatever further processing you want done.
Obviously, this can't happen straight away, because you would end up killing off every session almost as soon as it's created - even if the visitor is still around.