Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

So I've got a 13" Macbook Air with 128GB, and recently I got a message showing that I'm running out of space, so I did a quick check to see what was taking up all of space, and I found out that I have 4GB of sleep image (which is normal), but 20 swap files, each taking up from 60mb to 1gb. With a small disk size, this is really unacceptable so I was wondering if it was safe to delete some of the swap files and let the system build them up. Or would a restart help (Though I'd prefer not, had a bet with my friend to keep my uptime as long as possible :p) Any suggestions appreciated.

share|improve this question
    
Something will be leaking memory- you may be able to use this info to find out what. quora.com/… –  Danack Mar 9 '13 at 1:17
    
Well, what if it's the window server that takes up 4GB of virtual memory? And I don't think you can really fix a memory leak in another app right.. Guess I'll have to restart it, thanks anyway. –  theAmateurProgrammer Mar 9 '13 at 3:15
    
How to restart just WindowServer on OSX hints.macworld.com/article.php?story=20071121154033749 –  Danack Mar 9 '13 at 4:35

3 Answers 3

You can disable Hibernate to regain your size in RAM on your SSD/HD: First disable it:

sudo pmset -a hibernatemode 0

Then free up space:

sudo rm /var/vm/sleepimage

... if you want to enable it again:

sudo pmset -a hibernatemode 3

Note: -a means on charger and on battery, -b means battery and -c means with charger.

Alternatively if you have more than one disk you can symlink sleepimage to an HD so it can physically locate there.

Swap

First disable Swap:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Later delete the files:

sudo rm /private/var/vm/swapfile*

... if you want to enable it again do:

sudo launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
share|improve this answer
    
Although under Mountain Lion the sleepimage comes back –  Mark Apr 17 '13 at 22:40
    
Didn't know Mountain Lion doesn't obey it. –  KariNeko Apr 17 '13 at 23:13

A restart will definitively solve the issue.

Even if you kill the offending process, the system won't clear up the swap files - you need a reboot to do that.

Also, deleting the swap files would be a bad idea. You would need to sudo to do it, and if the system has the file open, even if you rm the file, it'll still be kept around as the file handle would be open, so you wouldn't gain the space back.

By all means try it, but it's not recommended :)

share|improve this answer
    
OSX will clear up swap files if a process is killed. –  Mark Apr 17 '13 at 18:40

You can delete the sleepimage without damaging anything. The system will recreate it over time. Usually when I get a message that I'm running out of space I just go to the terminal and type sudo rm /var/vm/sleepimage and I get about 9 gigs back but the system will rebuild it over time, so it's only ever a temporary reprieve.

To finish answering your question, and to let you know why you should trust me, you can delete every file in var/vm because they are caches of what is stored in your RAM currently. They are not critical... unless you lose power, and in a restart, most of the var folder is cleared automatically. Though, to provide users with steady reporting of their free space, OS X Lion and newer do not delete the older vm files at startup.

Basically, you'll always have VM files with size roughly equivalent to the amount of RAM you have used running programs. You can delete these and upon the next significant background activity event, the computer may re-create them. If you only have one program running, and doing nothing, but have huge VM files, that may be a sign of a memory leak in a program, but I have noticed that a lot of the preference panels and plugins on the menu bar are really huge memory hogs: If you run the Google Drive Synchronizer thing and the Dropbox app and the box.com app then those will call home 24/7 and move files around non-stop. They are more than enough activity to generate legitimate and huge VM profiles.

Hope that helps!

share|improve this answer
    
Thanks! It's funny, because I've had all of my apps crashed because my laptop ran out of space with 100 mb free, but 2 minutes later I have 8 GB free. Will do a backup first, and then try to delete the swap files. –  theAmateurProgrammer Mar 12 '13 at 11:56
1  
The swap files contain data that is not currently used in real memory but when that data is needed this will be swapped back into real memory. Swap files should not be deleted they are not caches that will be recreated/ –  Mark Apr 17 '13 at 18:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.