There are two major misconceptions that are often seen in relation to memory management:
- Full RAM is bad.
- Full swap is bad.
Both are wrong.
RAM is extremely fast compared to other types of storage, both latency-wise and bandwidth-wise. RAM is also extremely expensive compared to other types of storage. Hence, you want RAM to be always full, otherwise you are wasting fast and expensive storage.
Swapping is bad. Swap isn't. Most OSs will flush pages from RAM to swap preemptively during periods of low system load but keep them in RAM at the same time as well. Why? Because swapping is slow, and thus you want stuff be already in swap in case the proverbial feces hit the proverbial air circulation unit. You don't want your system to start swapping out at the same time when it is already under high load anyway.
So, an OS will try to use as much RAM as possible by e.g. caching recently and regularly accessed files in RAM. And it will try to use as much swap as possible by preemptively copying data from RAM to swap, so that if the OS needs the RAM quickly, it can simply use it for a different purpose without having to save it to swap first.
Now, when I wrote above that the OS will try to use "as much RAM as possible", that is not 100% true. It is more like the OS will try to use "as much RAM as it deems sensible", and defining what, precisely, "sensible" means is one of the things that performance engineers and kernel developers have been trying to improve upon ever since memory management was invented some 70 years ago.
MacOS in, particular, will try to keep some amount of RAM free, and will also compress some parts of RAM.