It has always been said that the RAM is there to use it. Of course, this is valid when we have a computer with enough memory to not be watching what happens with it. When we're a little tighter, it's worth taking care of it a bit, in the sense that we have to watch how busy we are and, whenever possible, make sure our team can get some air.
Sometimes, the system does not release RAM memory that is no longer being used and although it is released on demand —to call it somehow— when we open a new program, it can also be released manually by entering a simple command in our console. In theory, this behavior is common in almost all operating systems, and it makes sense: to be able to go faster when we want to access something we just used again.
Find out how much is in use and then free up RAM
First of all, stop know how much memory is in use, how much is free and how much is saved in the cache we execute the command:
To see the use in real time we use:
watch -n 1 free -m
The first command will return something similar to what we see in the header capture, while with the second we will see something very similar, but it will move in real time.
As can be seen, there is a large amount of cached memory, about half of which is being used by open applications. For release cached pages, inodes, and directory entries, just run the command:
sudo sysctl -w vm.drop_caches=3
It is important not to forget to run "sudo sync", or else we could lose information present in RAM that has not yet been saved to the hard drive.
Closing unnecessary processes
Ubuntu, and Linux in general, manages RAM pretty well, so you usually don't need to do any of the above. It can be different if the operating system does not know what to do with a heavy workload. That is to say, when we have many programs open, the operating system cannot or is not the one to decide what to do with each of them, and it tries to move them as it can. If there is no RAM, it will probably "decide" on its own to close some program, but this can cause us to lose some information.
Therefore, and as on so many occasions, the best way to manage RAM memory is head. If we have a computer with at least 16GB of RAM, we will rarely run out of memory if we do it in normal use, but with 4 or less, things are different. In these cases, it is best to have open only what is necessary.
If we notice that the computer suffers, we can open the task manager and see what is happening:
In the system monitor, a graphical tool (GUI) that shows us information similar to that of htop, we will see all the processes that are open. We can order them by name, by user, CPU or RAM usage, among others. If we notice that our computer is slow or has a hard time working, we are interested in ordering the processes by processor use (% CPU) or RAM (Memory). If we know what a process that is consuming a lot of resources is doing, we can right-click on it and choose the “Kill” option. Of course, saving before all the important changes.
If you look closely at the information offered by the system monitor or htop, among others, we will learn what consumes the most. From here, a recommendation for the owners of a low-income equipment is that have a good control of the web browser. Although it can be used to do everything and today it is one of the best work tools, it can also have many open processes that can leave our computer speechless. Therefore, it is worth not having many tabs open if they are not needed, and even closing the browser entirely.
RAM is there to use it, but not to waste it or make us suffer.
More information - Check the temperature of your computer with the command 'sensors'