Why do I get back more disk space when I restart my Macbook on Mountain Lion 10.8.3?

When the OS is low on memory it creates a file called a swap file, aka virtual memory on your hard drive, and in OS X this starts at some amount (I think 64 MB) then double as needed. So if you have 8 GB of RAM, you could end up with an 8 GB swap file. This is then deleted when you reboot.

You can read about it on http://en.wikipedia.org/wiki/Paging

Where the files are located and how to disable it: http://osxdaily.com/2010/10/08/mac-virtual-memory-swap/


As @pg-robban suggested, the most likely cause of this is that the system's swap space is growing until it fills the HD. To check whether this is really what's going on, run the Activity Monitor utility, select the "System Memory" tab at the bottom of its window, and check the "Swap used" statistic; if it grows as you use the computer, that's what's eating the HD space.

If that is the problem, the next step is to figure out what's eating all of the space. In Activity Monitor, switch the pop-up menu near the top of the window to "All Processes" and sort the process list by the "Real Memory" column. Unfortunately, this number doesn't include swap usage, but it's still a pretty good guide to which programs are using the most memory (the "Virtual Memory" column is not particularly useful, since it includes some categories of "memory" that don't take up any actual space, either in RAM or on HD).

It's likely that some program is leaking memory, i.e. using more and more as it runs. It may be that you can quit that particular program and reopen it and get its memory usage to go back down. Depending on what program it is, you it might be possible to figure out why it's leaking memory and fix it (unless the program is just plain buggy/badly designed).

Note that quitting & reopening the program won't recover the HD space (at least immediately). OS X is fairly lazy about releasing swap space when it's no longer needed. But if you make a habit of quitting & reopening the program frequently so its memory usage never gets too big, the OS shouldn't have to allocate the swap space in the first place.

BTW, you can get slightly more info about the system's swap file with the command sysctl vm.swapusage. For example, my Mac currently has 1GB of HD space allocated to swap, but it only using 470MB of it:

$ sysctl vm.swapusage
vm.swapusage: total = 1024.00M  used = 470.80M  free = 553.20M  (encrypted)