Ubuntu, Debian force / allow to free memory in RAM, Regular cleanup keep best performance. Memory management need very careful with some expert watch when working on production.
sudo sync & sysctl -w vm.drop_caches=3
This command syncronize 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:
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:
vm.drop_caches=3 free pagecaches, dentries and inodes.
vm.drop_caches=2 free dentries and inodes.
vm.drop_caches=1 free pagecaches.
Notice: 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.