Is there any way to manually clean up the memory other than a reboot?

I find that my memory gets cluttered with a bunch of junk, even if I close all of the applications and the only way to get it cleared up is to reboot the system. It seems that there should be a way to clean up memory without rebooting.

Mac mini, OS X El Capitan (10.11)

Posted on Jan 23, 2016 3:59 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 24, 2016 9:24 AM

In that case there is a program or process leaking memory. That means it is not releasing memory when it should, and is considered a bug that only its developer can fix. Minor memory leaks are not unusual, but not to the extent you describe. Determining which program or process can be challenging.


You can use the command leaks to identify whether a specific process is doing that, but its results can be inconclusive, and you have to know in advance which process you suspect is responsible. Most likely it will be a non-Apple product, though certain Apple software has been known to leak memory in rare circumstances.


To potentially identify likely culprits use Activity Monitor, click the Memory tab, and sort processes by memory. Start by identifying the process with the largest memory value other than kernel_task.


Compressed memory refers to memory that has been compressed using OS X's proprietary compression algorithm. Virtual memory refers to memory contents that have been written to mass storage, which is slower than RAM. If your Mac uses a rotational hard disk drive virtual memory usage will be very slow. Compressed memory is normal and your Mac's performance will not be affected by memory compression. On the other hand if the "memory pressure" graph becomes "red" it's an indication that your Mac is relying upon virtual memory, and its performance will degrade.

27 replies
Question marked as Top-ranking reply

Jan 24, 2016 9:24 AM in response to Whickwithy

In that case there is a program or process leaking memory. That means it is not releasing memory when it should, and is considered a bug that only its developer can fix. Minor memory leaks are not unusual, but not to the extent you describe. Determining which program or process can be challenging.


You can use the command leaks to identify whether a specific process is doing that, but its results can be inconclusive, and you have to know in advance which process you suspect is responsible. Most likely it will be a non-Apple product, though certain Apple software has been known to leak memory in rare circumstances.


To potentially identify likely culprits use Activity Monitor, click the Memory tab, and sort processes by memory. Start by identifying the process with the largest memory value other than kernel_task.


Compressed memory refers to memory that has been compressed using OS X's proprietary compression algorithm. Virtual memory refers to memory contents that have been written to mass storage, which is slower than RAM. If your Mac uses a rotational hard disk drive virtual memory usage will be very slow. Compressed memory is normal and your Mac's performance will not be affected by memory compression. On the other hand if the "memory pressure" graph becomes "red" it's an indication that your Mac is relying upon virtual memory, and its performance will degrade.

Jan 24, 2016 10:23 AM in response to Whickwithy

I'm still waiting for you to describe the likely process or processes identified by Activity Monitor. Until then you cannot even get to Step 1.


I recommend you forget about "cleaning up" memory. It is not necessary to concern yourself with such minutia, despite a plethora of popular "cleaning" apps that seek to convince gullible users of their benefit. Attempting to circumvent OS X's memory management will always lead to performance degradation, as well as the likelihood of accelerated hardware failure. If your Mac's performance begins to degrade for reasons you cannot explain, we can help you to troubleshoot that.


All I can tell you is that El Capitan runs perfectly well in 4 GB RAM, running mostly (though not exclusively) Apple software, with no apparent leaks or degraded performance. I have tried and failed to degrade its performance by simultaneously running literally every app that I have installed. Of course flash memory helps.


Here is a screenshot of AM:


User uploaded file


This particular Mac has been up for 10 days:


Last login: Thu Jan 14 10:16:10 on console

Restored session: Mon Jan 11 23:55:05 EST 2016

MacBookAir2:~ john$ man leaks

MacBookAir2:~ john$ w

12:13 up 10 days, 1:57, 2 users, load averages: 1.53 1.45 1.41

USER TTY FROM LOGIN@ IDLE WHAT

john console - 14Jan16 10days -

john s000 - 9:31 - w

MacBookAir2:~ john$

Maybe that will get you pointed in the right direction. Good luck.

Jan 25, 2016 7:39 AM in response to coltrane58

coltrane58 wrote:


it is a terminal commad. you must run it as root so you must have root enabled. Then open a terminal window and run:

sudo purge

it will prompt you for the root password.

To enable root see: https://support.apple.com/en-us/HT204012

You DO NOT need to enable 'root' in order to use the 'sudo' command. Disabled 'root' just means it does not have a valid password and you cannot login to the account. However, the 'root' account is still there, and there are many processes already running as root.


sudo ONLY needs your admin account password, and will then elevate you to root privileges.


Unless you really have a need to have a root GUI login, you should NOT enable root. It is a well known account name and frequently gets probed by script kiddies to try and break into Unix systems. Your username is not will known, so script kiddies would need to guess your username and then guess your password. That is a much larger name space to explore. Keep root disabled. Use sudo when you need to be root.

Jan 24, 2016 9:57 AM in response to Whickwithy

OS X's memory compression algorithm really will have negligible effect on performance. I have quantified it, and it is essentially zero. You are welcome to do so yourself.


Compression will not occur unless you need more memory than you have. Adding more memory will delay the onset of memory compression. However, it is not a cure for memory leaks. If a process is leaking, it will take all available memory... eventually. If that "eventually" is on the order of weeks or months it's not worth investigating. Rebooting every so often, even if it's in response to an OS X update, is normal.


They are all pretty standard programs.


If to you "pretty standard" means products from Adobe, Google, or Microsoft, anything is possible. None of them have demonstrated any particular aptitude for — or apparent interest in — developing efficient OS X programs. "Anti-virus", "cleaning" products or similarly ill-conceived garbage is even worse. Identify the suspect processes using Activity Monitor as I suggested.

Jan 24, 2016 12:40 PM in response to Whickwithy

1. Apple finds a way to clean up leaks or

2. Safari adds cookie control and there are no leaks.

Apple cannot fix leaks in other developer's software.


Apple does not control the Javascript web sites send to the browser.


If OS X refuses to give the memory an app or Javascript is requesting, then the app will break. Then users will complain that Apple broke their app. And even if you thought that was a good idea, where do you draw the line. An app that does next to nothing need very little memory, but a movie editing app can consume all the all the RAM in your future 64GB Mac Pro. How does OS X decide a request for RAM is too much?


I'm saying this as a software developer. It is easy to say these things and much more difficult to create a policy that works and is pain free.


And if you are going to suggest each app have a controllable limit, the pre-Mac OS X (Mac OS 9 and below) had this feature, and it was a pain to administer. And most likely generated lots of support calls to Apple and developers, especially when you consider that sometimes the amount of memory an app needs is a function of what the use does with it.

Jan 24, 2016 9:31 AM in response to Whickwithy

Do you honestly think that compressed memory is as slow as swapping to disk? dream on.


And if you do you can turn it off.


  1. Open up Terminal
  2. Type in: sysctl vm.compressor_mode
  3. (you should see 'vm.compressor_mode: 4' here, which indicates compressed swap is enabled)
  4. Type in the following: sudo nvram boot-args=vm_compressor=1
  5. reboot
  6. After reboot, verify it worked, open up Terminal, and do 'sysctl vm.compressor_mode'. You should see 1 printed.

Jan 24, 2016 3:23 AM in response to John Galt

I am referring to ram, yes, John. The problem is this.


I start my computer and the memory used is about 4 Gbytes with just the most basic programs open. After a few days, when I return to the same set of basic programs, the computer now takes up about 6 Gbytes. A few days after that, it's at 8GB. You see the trend, I think. This is a bad thing because, sooner or later, I start using compressed memory, which I assume is Apple's way of saying virtual memory or, even worse, they use some sort of compression scheme. In any case, if I am using so much memory that it goes compressed, it is making the machine slower and will eventually cause disruptions, as well. Getting rid of all of that wasted memory usage that is just cluttering up my ram, in some circles, used to be called garbage collection. Now, I guess it is called reboot.

Jan 24, 2016 9:24 AM in response to John Galt

Compressed memory refers to memory that has been compressed using OS X's proprietary compression algorithm. Virtual memory refers to memory contents that have been written to mass storage, which is slower than RAM. If your Mac uses a rotational hard disk drive virtual memory usage will be very slow. Compressed memory is normal and your Mac's performance will not be affected by memory compression. On the other hand if the "memory pressure" graph becomes "red" it's an indication that your Mac is relying upon virtual memory, and its performance will degrade.

So, compressed memory is as I suspected. It has to have an effect. Any messing with the memory, such as virtualizing it or compressing it, is not optimum and I never let it take place. "Normal" is not accurate as it does not attempt to compress it unless there is some level of memory pressure, though it is a very small amount. My memory used gets to about 10 - 12 GBs before it attempts to compress. And, that's when I reboot.
Thanks for the insights, I may look at the "leaks" stuff you talked about. I think we are looking at things from a different perspective. You are looking at it from the perspective of recovering from slowness or failure. I am looking at it from the point of view that I don't ever want to incur either. So, I don't think I have any specifically leaky programs. They are all pretty standard programs. It just I don't like to tolerate any leakage. I use the programs pretty intensely and look for any use of compression and reboot.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Is there any way to manually clean up the memory other than a reboot?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.