When your Mac is slowing down, try this Terminal tip

This is one of the most useful Terminal tips youâll ever come across. Itâs the go-to fist stop solution if apps like Safari start to hang, Mail starts to freeze, or applications otherwise become less responsive than normal.
What is the problem?
Macs just run and run. Thatâs great, and thatâs why so many Mac users rarely switch their computers off. Thatâs fine too, as these systems can handle that, but after youâve been using them for an indeterminatewhile you may find that they become less responsive. Usually this is because one or more of your apps has taken RAM from your system in order to run, but failed to release it back when it ceased to be the active app. The end result? After some time your Mac wonât have the memory it needs to run things efficiently.
Hereâs what to do
You can restart your Mac to flush your systemâs RAM if you like, though youâll need to quit and restart all your applications which will use precious time. Or try this Terminal tip:
- Launch Terminal (Command-Spaceand type âTerminalâ, hit Return)
- In the Terminal window, type âsudo purgeâ (without the quotation marks) and hit Return. (On versions of OS X prior to Sierra just type âpurgeâ.) WARNING: Do not mistype this as very bad things can and will happen
- Youâll be asked to enter your password (it wonât show as you do, so type carefully), hit Return.
You wonât see anything happen, but if any of your apps are using memory they donât need to be using it will be returned to the central pool.
This should have the same effect as restarting your Mac â with the advantage of not needing to relaunch your applications. And everything should then run a little more smoothly.
NB: This is particularly useful when working with older Macs.

This actually doesn’t clear memory but disk cache. From the purge man page:
purge(8) BSD System Manager’s Manual purge(8)
NAME
purge — force disk cache to be purged (flushed and emptied)
SYNOPSIS
purge
DESCRIPTION
Purge can be used to approximate initial boot conditions with a cold disk buffer cache for performance analysis. It does not affect anonymous memory that has been allocated through malloc, vm_allocate, etc.