I am new to Java, I just gone through heap dump analysis using eclispe's MAT. So i just wanted to below points a) understand what is Shallow and retained heap size and how it is being calculated? It would be great if you provide example. b) For performance issue,most of people adviced me to keep minimum and maximum heap size same, so is is ok or it is subjective to application to application?
-
See http://stackoverflow.com/questions/6862972/is-it-good-to-set-the-max-and-min-jvm-heap-size-the-same for setting min and max the same size. – Mark Aug 08 '12 at 07:39
2 Answers
Shallow heap is the memory consumed by one object
. An object needs 32 or 64 bits (depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted
Retained heap of X is the sum of shallow sizes of all objects in the retained set of X, i.e. memory kept alive by X.
Refer this link.

- 7,831
- 3
- 35
- 54
JVM sizing and tuning is not an exact science, so taking a blanket decision to set min and max size the same is not necessarily the best config to choose.
I find this to be an excellent explanation of the sorts of decisions that you need to make. In addressing your question, it says :
Setting -Xms and -Xmx to the same value increases predictability by removing the most important sizing decision from the virtual machine. However, the virtual machine is then unable to compensate if you make a poor choice.
If you set the min and max the same, but have an inappropriately sized Eden space, you may still end up with poor garbage collection performance.
The only way to make decisions about sizing is to run your application under a variety of workloads and see how the GC performs.

- 7,187
- 5
- 32
- 53