How to clear cached memory in Debian?

Try this as root (not sudo):

#sync && echo 3 > /proc/sys/vm/drop_caches

The problem with:

sudo echo 1 > /proc/sys/vm/drop_caches

is that the redirect happens in the initial shell - i.e. under your own account - before the "sudo echo 1" happens, which isn't the part that really needs root access. You need to get the opening of drop_caches by ">" to be inside of the sudo. One lazy way (lazy because it clones the 3 back to stdout, which you don't actually need) is:

echo 3 | sudo tee /proc/sys/vm/drop_caches

The options to write into drop_caches are:

  1. Free pagecache
  2. Free dentries and inodes
  3. Free pagecache, dentries, and inodes.

And you should sync first, so all in all:

sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches

or if you don't like the spurious "3" on stdout:

sudo sh -c 'sync ; echo 3 >/prod/sys/vm/drop_caches'