Open Laboratory for Technocrats

Grab the developer role, learn concepts & prepare with senior software engineers to get solutions for problems in a software job. Coding and Programming Solutions crafted for you.

UBUNTU RAM Cache Cleaner

It mostly happens in the low ram system that they are going out of memory. This was the case with me today and on digging to it figured out the my systems swap area and cache was occupying the most memory.

Instead of making this just one time solution I figured out to get the little hacky long term solution until I upgrade my system.

The tool called System Load Indicator is very helpful for the  testing of the command and its easily available on Ubuntu software center.

For allowing this command to run smoothly follow the steps as :
  • Open Terminal and be root with sudo su
  • Type command sync; sudo echo 3 > /proc/sys/vm/drop_caches
 This will free the RAM which  can be easily visible on the System Load Indicator. Otherwise  we can also use free command to see the difference before and after running the main command.

This will give you one time solution but for a constant solution we can make this command in cron list. So that it will run on desired time and make RAM clean.

We can add it to cron job as follows:
  • Open terminal as root user
  • Type: crontab -e
  • If asked to select editor select your favourite
  • Copy and paste this command as:  * * * * * sync; sudo echo 3 > /proc/sys/vm/drop_caches
  •  Save and exit
After exit you will see the message of installing new cron on the terminal and that’s it. You have installed a new cron job for RAM cleaning and it will run on the desired time as those five starts are the timing related which you can grab more here and here

Enjoy learning and keep exploring :)


Top #3 Articles

Most Read