We sometimes get queries about gaps in reference number sequences. Why would MoneyWorks be so dumb as to skip reference numbers?
In fact, reference number allocation is not that trivial.
Consider the situation where you open 5 new invoice windows. Each one gets an invoice number. Now close them all in random order by clicking Cancel. MoneyWorks has to do something with those invoice numbers, but what? If you cancelled them in reverse order of allocation, instead of random order, then they would go back into the sequence. Unless, that is, you are not the only user in a multi-user situation. Then it depends on whether anyone else has opened a new invoice window in the intervening time and taken a number from the sequence. If you did not close the windows in the exact reverse order that you opened them, then the relinquished "unused" reference numbers become available for reuse in a random order. The "Next Reference Number" that you would see in the preferences no longer has much meaning.
Since MoneyWorks does not have a special file in the database just for storing relinquished reference numbers, what it does is remember in your session what numbers you have relinquished. The stack of relinquished numbers is only kept until you quit or close the file. Within that time, if you make a new transaction then a number from your relinquished number stack will be used.
If you quit, you lose those numbers because they are only remembered for the session and the preference allocation number has moved on.
This happens even in single user mode due to the ability to have multiple open transaction windows. In multi-user each user might end up with a cache of reference numbers in this way.