Mac OS X 10.10.3 running out of disk space after sleep / Potential memory leak?

I have a MacBook Pro Retina 13" (Late 2013) with 16 GB RAM/512 GB SSD running Mac OS X 10.10.3. There are 20 GB free space on the SSD according to the Finder.

Despite the relatively huge amount of available disk space I constantly get the "Your startup disk is almost full" alert after waking up the MacBook from sleep. I can then observe in the Finder that only approx. 100-300 MB are available in that very moment, but that within seconds space is freed again, though not the entire space (for example 6 GB become available). It requires a restart/reboot to make the entire 20 GB to reappear.

I'm a hardcore Safari user (a dozen windows open with 1 to 25 tabs in each) and also have ten thousands of mails in my 10 email accounts in Mail.app. I'm also aware that Mail.app retrieves mails while the MacBook is closed, yet I still can't believe that this is what eats up all the disk space. The interesting point is that it only gets dramatically low during/after sleep. When actively using the machine the free space decreases, but never to that degree that the said alert pops up.

I got the strange feeling that one of the various extensions might be the responsible resource hog. How can I nail down who or which app (or if Safari: exactly which browser tab) is responsible for this? Exactly how and where to look in Activity Monitor!?

Swap files? Uhm, yes... But which app and why during sleep!?

Just learned about the existence of a "Sleep image" which likely is to save the state in case the machine runs entirely out of power. Still I'm worried about a memory leak as there is dramatically less space available after a while of using the machine compared to the situation after any reboot.


Solution 1:

The purpose of the sleepimage is to store the contents of RAM if your Macbook's battery is low and is about to turn off completely (what Apple call "hibernate"). As such it can be equal in size to the amount of RAM in your Mac. So on your Macbook with 16GB of RAM it could be 16GB in size, which would go a long way to explaining how your Mac with 20GB of free space could quickly fill up. You can check the size of the sleepimage by typing ls -lh /private/var/vm/sleepimage in the Terminal. You can also delete it at any time with sudo rm /private/var/vm/sleepimage as your Mac will just recreate it as needed.

About your Safari use... "a dozen windows open with 1 to 25 tabs in each"...

Have you heard the famous joke about the guy who goes to his Doctor and says "My arm really hurts when I do this" and his Doctor says "Well, don't do that."?

There is another slightly less famous joke about a guy who goes to his Apple Genius and says "My Mac really hurts when I open over a hundred tabs in Safari." and his Apple Genius says "Well don't open over a hundred tabs in Safari."

I might have made that last one up, but it sounds like good advice. You might want to get into the habit of closing tabs and using a bookmarking service like Pinboard or Instapaper.

If you have 16GB of RAM and the most commonly used applications on your Macbook are Safari and Mail, your Mac shouldn't be using a significant amount of swap files. Unless of course you have 100+ tabs open in Safari. You can check the amount and size of swapfiles on your Macbook with ls -lh /private/var/vm/ in a Terminal window. Note that they are in the same place as the sleepimage, but you can't delete them. If you reboot your Macbook it should clear them up itself.

Something else to try is running Etrecheck on your Macbook. It will identify a lot of the third-party extensions/plugins on your Mac, including Internet plugins. I'd start with removing the ones you no longer need or don't recognise.