I am running two Ubuntu 12.04 servers (no GUI / desktop) using canonical's cloud images on Amazon EC2. One is a micro with 613MB of RAM and one is a medium with 3.75GB of RAM.

I only have opscode's chef installed on the micro box, and on the large box I have a java app / SOLR index initialized with 2048MB of ram:

JAVA_OPTIONS="-server -Xms2048m -Xmx2048m -XX:+UseParallelGC -XX:NewRatio=5"

If I have had chef running on the micro box for a while, and then try and install a new program, or start up something like the RabbitMQ or Apache2 I will get an error about not having enough free memory to complete the operation.

On the large box, it seems that the Java application will periodically crash when the memory gets low, or after the box has been on for a while.

Using the free / free -m command I see there is in fact not much memory available, at which point I usually have to reboot the system to "clear out" the memory.

It seems to be that either the memory should be automatically freed or "cleared" after some point of time, or if it must be done manually there might be a better way to free up / clean/ manage the memory more efficiently.

Is there a way I can manually free up / clear the system's memory? Is there a tool that will check / clean the memory automatically?

  • could please update your question with the output from command "watch -n 1 cat /proc/meminfo" ?
    – MelBurslan
    Commented Mar 11, 2013 at 19:20

2 Answers 2


Needing to reboot certainly doesn't make much sense -- if your memory is full, it must be full of something, and if you stop that process (eg the java app), then that memory would be freed.

However, if you need to do this just so you can then restart the same app, there is the question of why the process would have grown to consume so much memory this way. Normally a process which just grows and grows and never releases anything might considered one which is leaking memory due to a bug internal to it.

Ie., the first thing you need to do is find out what software specifically is causing the problem; tools like top are commonly used for this. You might also be interested in plog.

  • it is a possibility that after stopping processes they would not free up all the memory they used?
    – cwd
    Commented Mar 11, 2013 at 21:07
  • @cwd No. A process which no longer exists does not use any memory. top (or htop) is a pretty basic diagnostic tool that you do need to know how to use if you are working on a linux server. Play around, get the hang of it, find out what the various metrics are (understanding the difference between virtual address space and physical memory is important), then next time you get "not enough memory" you will have some means of determining where it's gone to.
    – goldilocks
    Commented Mar 11, 2013 at 21:30
  • @cwd No, barring a kernel bug (which is technically possible, but very unlikely). Commented Mar 11, 2013 at 22:46
  • Best thing to do is restart the process and figure out why it uses so much memory. Example with httpd : service httpd restart
    – null
    Commented Jul 31, 2013 at 18:10

there is this harebrained idea I have read somewhere about dropping the caches but never tried it myself. At your own risk, you can try it :

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

basically, what you are doing here is, you are committing the disk write operations, cached in memory, to the disk(s) and clearing the cache memory portions. But if your system is configured normally, this should start building up as soon as you finish executing this command. But it might give you a momentary relief to overcome "not enough memory" message. And if committing to disk fails, drop cache command will not work as you can see from the command "&&", so it is rather a safe option.

  • 1
    Caches and buffers get flushed out if memory is needed. Dropping caches is useful for benchmarks and little else. It cannot help in an insufficient memory situation. Commented Mar 11, 2013 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .