One of the most common reasons for deleting files is to reclaim the space they occupy, so it can be reused for other files. There are occasions, though, when that aim will be frustrated, and for the time being at least, there won’t be any resulting increase in free space. Here are some examples you’re likely to come across when using APFS volumes in your Mac. Only one of these (hard link) also applies to HFS+.
In a snapshot
The requirement for any snapshot is that it must retain file system information and file data to allow that volume to be rolled back to its state at the time the snapshot was made. Although that might seem simple, in practice it can become confusing.
The simplest case is a file created and saved just before the last snapshot was made. If you were to delete that now, no real space would be freed yet, as its entire data has to be retained until that snapshot is deleted, and only then will that free space be realised. Because snapshots and their contents are considered to be purgeable, the space taken by that file is included in the total purgeable space for that volume.
Real life is often more complicated, as I showed when downloading 26 GB files. A snapshot made after downloading only 10 GB of a 26 GB file captures only what was saved to disk at the time the snapshot is made. If that file is then deleted before the next snapshot, that immediately frees the last 16 GB of the download, but retains the first 10 GB until that snapshot is deleted. As you’re unlikely to be aware of how much was captured in a snapshot, that may appear almost random in its effect on free space.
You can get an idea of how much is retained in each snapshot by inspecting their Private Size in Disk Utility, with Show APFS Snapshots enabled.
Clone file
Clone files start off life as two distinct files with their own file system entries sharing all the same data. At that stage, deleting either of them will free no space at all, as all the data has to be retained for the surviving clone.
Clone files tend to diverge with age, as you edit either or both of them, until eventually they may have no data in common. At that stage, deleting either of them will free the full size of its data, as none of it is shared with the surviving clone.
Unfortunately, it’s non-trivial to work out how much data remains in common between two clones, and thus predict how much could be freed on deletion. So you should consider that as an unpredictable range, anything between zero and the full size of the clone that’s deleted.
Sparse file
Sparse files are the most efficient way to store files with relatively small amounts of real data embedded in a mass of null data. Rather than waste space by storing all that null data on disk, a sparse file’s data is limited to what’s real. This is the one case where the Finder can provide a reliable estimate of how space will be freed when a file is deleted. Select the file and Get Info for it. In the General section, you’ll something like
Size: 107,374,182,400 bytes (34.01 GB on disk)
The first size given is nominal, the total including all the null bytes that aren’t stored. That given on disk is the amount of space that should be freed when that file is deleted. So in that case, deleting a 107.37 GB sparse file will only free up 34.01 GB. Those are real figures taken from a macOS virtual machine’s virtual disk. Not all sparse files are as space-efficient, and some save less than 5% of their nominal size.
Hard link
These can only be created at the command line, not in the Finder, and appear similar to clone files, although they’re very different. In a file system, files consist of an inode with its attributes, and file extents referencing its data. Clone files consist of two distinct inodes that initially reference the same data in their file extents. Hard links are additional inodes that refer to the same file, complete with a single set of file extents.
APFS implements hard links in an unusual way that makes this even clearer. When you add a hard link to a file, a Sibling reference is added to the file’s inode, and the inode’s reference count is incremented. When you delete a hard link, that Sibling is deleted, and the reference count is decremented to equal the number of siblings. When the reference count reaches zero, and there are no Siblings, the inode itself is deleted, together with all its file extents.
So deleting a hard link only removes its Sibling, not the file, nor its data, which is only deleted when the inode itself is deleted because there are no Siblings left.
The Finder doesn’t tell you which files are in fact hard links, nor does it reveal the reference count. My free Precize does, though.
Dataless file
When a Mac uses iCloud Drive and has the Optimise Mac Storage setting enabled, files in iCloud Drive can have their local data removed, a process termed eviction, leaving just the inode and its extended attributes without file extents, or dataless. These are distinguished by their cloud icon, and the Finder’s Get Info states clearly that they take no space on disk. Deleting them will therefore not return any free space at all, but will free space in iCloud Drive instead.
Summary
Deleting any of the following may not free up their full size immediately:
- a file that existed when the last snapshot was made of that volume;
- a clone file whose other clone(s) contain shared data;
- a sparse file;
- a hard link which still has other hard links, including the original, referencing it;
- a dataless file, which has been evicted from iCloud Drive.
