Access creates the compacted db as a new file, deletes the old (uncompacted) db file, and renames the new file to the old name.
It always works that way regardless of whether you compact from external code, from within an active Access session, or with compact on close at the end of an Access session.
With a small enough db file, the entire process can complete so quickly that you might not notice the transitional new db file. But with a large enough db file --- 1 GB should do it --- you can watch in Windows Explorer as the new db file is created and grows to it final (compacted) size.
Incidentally, be cautious about compact on close. Many experienced Access developers recommend against that option. The reason is that if anything goes wrong during compact, the new db can be corrupted and your original uncompacted version will be gone ... so no hope of recovery.