In Linux, you can free up RAM (release cached/buffered memory) without using sync or rebooting by using one of the following methods:
1. Dropping Caches (Recommended)
The Linux kernel allows you to manually clear PageCache, dentries/inodes (directory cache), and slab memory by writing to /proc/sys/vm/drop_caches:
Command:
sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
What it does:
echo 1 → Clears PageCache (file system cache)
echo 2 → Clears dentries and inodes (directory cache)
echo 3 → Clears both PageCache and dentries/inodes (most effective)
Notes:
- This does not terminate running applications; it just frees unused cached memory.
- The kernel will automatically refill caches as needed.
- Not harmful, but may cause a slight slowdown if files were recently accessed (since they must be reloaded from disk).
2. Using sysctl (Alternative to echo)
You can also use sysctl to drop caches:
sudo sysctl vm.drop_caches=3
3. Freeing Buffers & Cache (free -h Before/After)
Check memory usage before and after with:
free -h
- Before: High
buff/cache usage.
- After:
buff/cache should decrease, and free memory should increase.
4. Alternative: vm.drop_caches via /etc/sysctl.conf (Persistent)
If you want to automatically drop caches periodically, you can add this to /etc/sysctl.conf:
vm.drop_caches = 1 # (1=PageCache, 2=Dentries/Inodes, 3=Both)
Then apply:
sudo sysctl -p
5. Using swapoff -a && swapon -a (If Swap is Used)
If your system uses swap, you can clear it by:
sudo swapoff -a && sudo swapon -a
This disables and re-enables swap, forcing the kernel to move swapped-out data back to RAM (if possible).
Important Notes:
- This is not "cleaning RAM" in the Windows sense (Linux manages memory efficiently by default).
- Cached memory is good—it speeds up file access. Only clear it if you really need free RAM (e.g., before running a memory-intensive task).
- No need to do this regularly—Linux automatically reclaims memory when needed.
Final Recommendation
For most cases, just use:
sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
This is the safest and most effective way to free up RAM without rebooting. 🚀