I have Ubuntu 18.04

For example if Ubuntu is just started the Memory Ram has 2.0 GB, if I just open Firefox the component increases (how is expected) lets say to 2.5GB. If I close Firefox (Ctrl + Q), I would expect that the value returns to 2.0GB. Well it does not happen how is expected, for example: the Memory Ram returns to 2.2GB (and not 2.0GB).

I have this behavior with other programs apart of Firefox.

Is there a command where I can free in general all the memory ram? At least to the best acceptable minimum value according to the OS itself after to execute the command.

The goal is after to execute some "heavy" software development tools and servers (therefore when they have just been closed), release the best amount of resources of these two components.

Note: not sure if the Kernel has this behavior too (such as Kernel Task in MacOS), it because both are Unix based

  • 2
    Linux does cache stuff in memory, but will give up the memory if needed. If you want to force it do as sudo sync followed by echo 3 > /proc/sys/vm/drop_caches. Check before and after with free -m. – Doug Smythies Nov 5 '19 at 18:55

When a program terminates, RAM used by that program is freed. Memory used by shared libraries will be released if no other program uses that library.

If the data reads and writes data to disk, it will be cached if there's free RAM available. This cache will be kept until new data replaces it, or it is needed for programs and not caching.

To view the information, free -m will give you information.

$ free  -m
              total        used        free      shared  buff/cache   available
Mem:           5950        2292        1444           9        2213        3358
Swap:          4084         350        3734

In this case, the total amount of RAM is 5950MiB, 2292MiB is *actually in use, and 1444MiB is not in use in any sense. Additionally, 2213MiB is used for caching. The cache and free is available for immediate use, for a total available memory of 3358MiB.

When you exit your program, you will see that used drops, but the buff/cache column does not change. However, this doesn't matter, as memory used for cache is available for use whenever you need it.

So in short: Let Linux manage your memory. There's no need to do it manually.

|improve this answer|||||
  • I see the logic, thanks for the explanation, just being curious: from where exactly comes from 3358? It is a generated number by your report right? I mean, according with your context free + cache should give 3358, but really the math (1444 + 2213) represents: 3657 and not 3358 how is expected. – Manuel Jordan Nov 6 '19 at 0:46
  • 2
    @ManuelJordan : see the man pages for free, particularly the description for the "available field" because it is an estimate and takes other things into account. If you want more detail then do cat /proc/meminfo. – Doug Smythies Nov 6 '19 at 3:37
  • Thanks for the other command. I am going to do the respective research – Manuel Jordan Nov 6 '19 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.