Number Generation through Expression

When does the counter get set when creating a document number through expressions? I have noticed that whenever I create a new document and close the tab before saving the document, it increases the counter for the next document. I thought it set the counter at the time of saving.