Using Xms256M
and Xmx512M
, and a trivial program, freeMemory
is 244M and totalMemory
is 245M and maxMemory
is 455M. Using Xms512M
and Xmx512M
, the amounts are 488M, 490M, and 490M. This suggests that totalMemory
is a variable amount that can vary if Xms
is less than Xmx
. That suggests the answer to the question is to set Xms
to a small amount and monitor the highwater mark of totalMemory
. It also suggests maxMemory
is the ultimate heap size that cannot be exceed by the total of current and future objects.
Once the highwater mark is known, set Xmx
to be somewhat more than that to be prudent -- but not excessively more because this is an economization effort -- and set Xms
to be the same amount to get the time efficiency that is evidently preferred.