title: How to Instruct JVM to keep memory footprint as low as possible?
body: <p>I have a java program that performs 5 different tasks. When I run the program with -Xmx512m memory parameter, tasks 1-4 run fine but task 5 goes out of memory. When I run the program with -Xmx1024m, all 5 tasks runs fine but tasks 1-4 that previously ran fine with 512m heap now uses up almost all of 1024m heap. The same thing happens if I use -Xms128m -Xmx1024m.</p>
  
  <p>What would be the memory parameters to instruct JVM to keep the memory utilization low (e.g. 512m for tasks 1-4) and only to use more memory when actually needed (e.g. in case of task 5)? </p>
  
  <p>Maybe I need a way to activate the garbage collector more frequently than the default setting?</p>