I have read several forum posts where people have asked "How do I clear/free/dump/purge the memory cache?" A variation of the same answer is almost always given "You don't want to do that ... the Linux Kernel is smarter than you ... Don't try it ... Use dd to create a big file, then delete it ... etc ..." I never could find an answer that just explained how to do it, so I kept searching elsewhere, and here it is.
NOTE: This may cause you to lose data, it may make your system slower, it may kill your cat. Do this at your own risk, and don't be surprised if it doesn't work out the way you wanted it to.
With the CYA out of the way, here is how to free up as much memory as possible by dumping the cache. Execute as root, or with sudo:
That's it. Not much to see here. The first command writes any cache data that hasn't been written to the disk out to the disk. The second command tells the kernel to drop what's cached. Not much to it. This invalidates the write cache as well as the read cache, which is why we have the sync command first. Supposedly, it is possible to have some cached write data never make it to disk, so use it with caution, and NEVER do it on a production server. You could ... but why take the risk?
# echo 3 > /proc/sys/vm/drop_caches
As long as you are running a post 2.6.16 kernel, those commands will work. I tested it on Feisty and Gutsy, and it worked perfect.
I got this information from AP Lawrence.