Why does ubuntu not seem to release memory?

Solution 1:

You can free up unused memory using this command:

sudo sync && sudo sysctl -w vm.drop_caches=3

This command synchronize cached data and then writes an OS parameter at runtime, located at /proc/sys/vm/drop_caches. This parameter is read by kernel once, then free up the unused memory.

Basically, the kernel reserves three sections in cache, that could increase memory usage:

  • pagecache
  • dentries
  • inodes

Writing to this parameter will cause the kernel to drop clean pagecaches, dentries and inodes from RAM, causing that memory to become free. There are three values that can be assigned:

  1. vm.drop_caches=1 free pagecaches.
  2. vm.drop_caches=2 free dentries and inodes.
  3. vm.drop_caches=3 free pagecaches, dentries and inodes.

Important: After execution this will return to normal state which means start caching pagecaches, dentries and inodes again. Use it depending on your server configuration and application.