Skip to content

Instantly share code, notes, and snippets.

@sheecegardezi
Forked from harssh/free_memory.txt
Created November 17, 2025 07:24
Show Gist options
  • Select an option

  • Save sheecegardezi/a04d8e7910ceb3a6b3963bf32d564a4c to your computer and use it in GitHub Desktop.

Select an option

Save sheecegardezi/a04d8e7910ceb3a6b3963bf32d564a4c to your computer and use it in GitHub Desktop.
free up memory in ubuntu
Check Memory Usage in Real-Time
You can check your current memory usage using this command:
watch -n 1 free -m
This command will also display in real-time your system memory usage:
watch -n 1 cat /proc/meminfo
In the returned outputs, focus on these memory details:
MemTotal: 1027104 kB
MemFree: 302836 kB
Buffers: 24212 kB
Cached: 297364 kB
SwapCached: 0 kB
Active: 478336 kB
Inactive: 164844 kB
Free Up Unused Memory
Command 1
You can free up unused memory under Ubuntu/Linux Mint using this command:
sudo sysctl -w vm.drop_caches=3
NOTE: this action won't make your system faster nor it will affect its stability and performance, it will just clean up memory used by the Linux Kernel on caches.
Command 2
Here is another command that can help you free up memory either used or cached (page cache, inodes, and dentries):
sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches
NOTE: You can use cron jobs to schedule the commands above to run at specific time intervals.
If you have more useful commands for releasing/flushing memory in Ubuntu/Linux Mint, use the comment form below.
@sheecegardezi
Copy link
Author

Use systemd timer

Create the service:

sudo tee /etc/systemd/system/drop-caches.service << 'EOF'
[Unit]
Description=Drop caches

[Service]
Type=oneshot
ExecStart=/bin/bash -c '/usr/bin/sync && /usr/bin/echo 3 > /proc/sys/vm/drop_caches'
EOF

Create the timer:

sudo tee /etc/systemd/system/drop-caches.timer << 'EOF'
[Unit]
Description=Drop caches every 3 hours

[Timer]
OnCalendar=*-*-* 00/3:00:00
Persistent=true

[Install]
WantedBy=timers.target
EOF

Enable and start:

sudo systemctl daemon-reload
sudo systemctl enable --now drop-caches.timer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment