10
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.
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)?
Maybe I need a way to activate the garbage collector more frequently than the default setting?