What is this folder? It's huge and I can use the extra room. I've read sleepimage isn't necessary—is this true? Should I just deal with it? Is the "private" folder emptied automatically, or would I have to do it manually? If it isn't useful (or needed), is there any way to prevent it from reappearing in the future?
/var/vm/sleepimage is used to store the contents of the RAM during hibernation, and the hybrid hibernation and sleep mode that Mac laptops use by default. If you have 8 GiB of RAM,
/var/vm/sleepimage takes about 8 GiB of disk space. I don't know why it isn't deleted after waking up from sleep though. It might be to ensure that there is enough free disk space for it or so that it won't be stored on non-contiguous blocks if disk space is low.
You can delete
/var/vm/sleepimage safely, but it will be recreated when you put the Mac to sleep. If you run
sudo pmset -a hibernatemode 0; sudo rm /var/vm/sleepimage, the Mac will use a normal sleep mode (like desktop Macs by default) and it won't recreate
hibernatemode = 0 (binary 0000) by default on supported desktops. The system will not back memory up to persistent storage. The system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.
hibernatemode = 3 (binary 0011) by default on supported portables. The system will store a copy of memory to persistent storage (the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from disk image.
hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The system will store a copy of memory to persistent storage (the disk), and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps, slower wakes, and better battery life, you should use this setting.
- 0 (traditional sleep mode) enables fast wake up and sleep, saves disk space, and reduces writing to the drive.
- 3 (hybrid hibernation and safe sleep mode) enables fast wake up and sleep and enables restoring state after a power loss.
- 25 (hibernation) saves energy and enables restoring state after a power loss.
I used hibernatemode 0 with my MacBook Air. Even if the MacBook Air went to sleep when the battery was nearly empty, the battery didn't usually drain out completely during sleep.
/var/vm/sleepimage took about 4 GiB of disk space, and writing it hundreds or thousands of times might have reduced the lifespan of the SSD.
Addition: What Dan Barrett said about the sleepimage re-creation is true. However there's a way to get around it and therefore permanently free the disk space occupied by sleepimage.
The whole steps:
disable hibernation mode:
sudo pmset -a hibernatemode 0
sudo rm /private/var/vm/sleepimage
create an empty file and name it 'sleepimage':
sudo touch /private/var/vm/sleepimage
change its flag to immutable:
sudo chflags schg /private/var/vm/sleepimage
In this way the system cannot re-create sleepimage anymore. This worked perfectly for me and I've not seen any problem on my Mac for 4 months.
An additional note to the top answer:
Since you can either choose to disable the sleepimage, or activate it but then be forced to keep it after wake up, i found a dirty little trick for my preferred solution: Have a sleepimage but delete it after wakeup to free the disk space. If you are someone like me who constantly hovers at around 2-6 GB free space on your small SSD, this might be your solution.
Just point the sleepimage to your
.Trash folder and empty your trash bin after wake up.
sudo pmset -a hibernatefile ~/.Trash/sleepimage
This is only a viable solution, if you only use one account on your mac. You wont be able to easily delete the sleepfile from another account (Of course you could if the other account has sufficient rights, but it would loose it's simplicity because it would not just mean clicking on the trash bin).
If for whatever reason you want to return to the factory settings, just type
sudo pmset -a hibernatefile /var/vm/sleepimage
(Note: I use 10.8, this might change in other versions, just check
man pmset to be sure.)
If it's not taking too much space (like in your case) I would leave as it is. Things in the private folder are not meant to be messed with. It's part of the UNIX system your Mac is build on and shouldn't be visible. It's why they call the folder private. But software, like you used, made it visible, which is not a good thing.
That being said, you can delete this sleep image without any problem, but I wouldn't recommend it. If you really need those 4GB, try to use a hard drive for your movies, music or so and save space with your own files, not the systems files.