Ideally, just before closing our client connection, we should send a presence to the server to tell it that we are going offline, as follows:
<presence type='unavailable'/>
However, XMPP servers will generally send this to all your contacts when it detects that your client connection is closed on your behalf (including those contacts you've sent a directed presence to).