Accepted answer

your program doesn't run in eclipse's heap space. eclipse spawns off a separate jvm for your program.

runtime.totalmemory() does indeed return the current heap size.

the -xms argument specifies the initial heap size. java will expand if it cannot free up enough memory through garbage collection until it reaches the maximum, as set by -xmx. at this point, the jvm will exit with an outofmemoryerror.

java memory management is a complex topic, involving garbage collection, moving objects from nursery to tenured space, etc.

Related Query

More Query from same tag