Friday, February 2, 2018

How is free space reclaimed when files are deleted in Windows?



Whenever I delete a large set of files (multiple GB) I noticed that this doesn't free space as much as I would expect.
My expectation is that if I delete a certain amount of data my free space will go up with the same amount.



However, if I delete 5GB of files, empty the trash and look at the free space on my hard disk, it hasn't gone up with 5GB.
This happens both on Windows XP and on Windows 7.




So what happens with the space that the deleted files were taking in? Why is there no one-to-one relation between the amount of data deleted and the amount of free space reclaimed?



I found similar questions for Mac and Linux, but not for Windows.
I use the Windows Explorer for determination of the file sizes and free space.


Answer



There are a couple of things to consider here.




  1. Files may be counted twice or more due to hardlinks/symlinks


  2. If "System Restore" is enabled Windows may retain a backup-copy in a hidden location.

  3. Files can be allocated "sparse" which means that unused blocks within the file are not really allocated on-disk. The size shows as the "total" size of the file, but when deleted only the used parts are freed, so there is less gain than expected.

  4. Files can be compressed, so the actual space they take (and which is freed) is substantially less than the reported size.

  5. The MFT (which is an area on disk where NTFS keeps its internal administration) can grow and/or get fragmented which, under some conditions, can mean it grows when you delete files. (Should not make a huge difference though.)

  6. If you delete a file which is still in-use by a program, it can be that the file appears to be deleted, but it will not be really freed until the program releases/closes the file.

  7. Last but not least: In some cases file-system corruption may cause an incorrect reporting of the free space. A "Chkdsk /f" or a "Check & Repair" via the disk-properties gui should sort that out.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...