title: Java "Out of memory error" - heap/system - where to look?
body: <p>In my Tomcat application I am eventually getting "Out of memory" and "Cannot allocate memory" errors. I suppose it is nothing to do with the heap as it completely fulls up the system memory and I am hardly able to run bash commands.</p>
  
  <p>How this problem is connected to the heap? How can I correctly set up heap size so that the application has enough memory and so it does not consume too much of the system resources?</p>
  
  <p>Strange thing is that "top" command keeps saying that tomcat consumes only 20% of mem and there is still free memory, once the problem happens.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: </p>
  
  <p>Follow-up:
  <a href="https://stackoverflow.com/questions/10906223/bufferedimage-leaks-are-there-any-alternatives">BufferedImage leaks - are there any alternatives?</a></p>