If you've been close to the computers long enough, you've probably heard the phrase "have you tried turning it off and on again?" This trick usually works because it forces the computer to empty the contents of its RAM and disk cachs when restarting.
When you run programs and perform other activities on the computer, content of different types is loaded into RAM and disk cachs, and when you leave a running program, all loaded content must be purged from memory.
OS X is responsible for memory management (downloading RAM contents and disk cache), and proper memory management is crucial to ensure that the computer functions properly. OS X does a pretty decent job of memory management, but it's not perfect.
Sometimes RAM and disk cachs are not emptied properly, even though they are supposed to do so (such as when you exit a running program), and this can cause problems. To remedy this, you can force your Mac to clean RAM and disk cachs without rebooting, which can be very useful if you want to give your system a "boost" of performance without rebooting.
Step 1: Start Terminal
Terminal is a program that allows you to perform command line operations; Release it to start. You can find it in your Utilities folder in Applications, on your Launchpad or through Search in Spotlight.
Depending on your customization settings, the Terminal window may look different.
Step 2: Start the purge
Now, just type sudo purge inside the Terminal window and press Enter. This will begin the process of cleaning the contents of the RAM and the disk cache.
A message will appear asking you to enter your password. In OS X 10.9 or higher, this command requires an administrator password, hence the use of sudo. Go ahead, type your password in-Terminal do not show your password for security reasons. When you're done, press Enter again.
To make this process even faster …
Try to create an application or service in Automator. Although it may take 5 to 15 seconds to perform the previous task in the Terminal every time you want, you can create a shortcut that will take more than 2 to 5 seconds at a time with an easy click action.
To create a service, open Automator and choose to start a "Service". Then, drag "Run AppleScript" to the right panel and use the code shown below in the box. Then gurdalo as "Sudo Purge" or "Purge" or whatever you want to call it. When you want to use it, you just have to select the name of the application that is selected in the mens bar, select «Services» and then the name you have given it.
To create an application that you can click from your Dock, or anywhere, open a new file in Automator, select "Application" and do exactly the same as before. It will be saved as an Automator application that you can place wherever you want. You can also change the application icon if you want.
Limitations of the purge command
The purge command may be useful, however, it has some limitations. The most prominent advantage of the purge command is that it eliminates the contents of RAM and disk cache used to improve system performance. However, OS X in recent years has become much smarter with memory management, which should cover many usage scenarios.
Naturally, the purge command is not a substitute for ms RAM. For example, if you are editing video with only 4 GB of RAM, then updating your current configuration so that you have more RAM available will make more sense instead of continuously using the purge command.
In some cases, it is necessary to restart the system. For example, if for any reason you need to empty everything in RAM and disk cachs, you should restart. In addition, as already said, Terminal is a powerful tool, so if you don't feel comfortable working with the command line, then maybe you should avoid using it for now.
Still, the purge command, in the right circumstances, can be a useful trick to help give your Mac that second air it sometimes needs.