Char arrays make up almost 70% of memory usage (!), While a string field is about 7%
This is the subtlety of memory profiling, known as "saved size" and "small size":
- Shallow size refers to how much memory an object occupies, not including any child objects that it contains. This basically means primitive fields.
- The saved size is the small size plus the size of other objects referenced by the object, but only those other objects that relate only to this object (it is difficult to explain, a simple concept).
A string is a great example. It contains several primitive fields, plus char[] . char[] takes into account the vast majority of memory usage. The shallow size of the String is very small, but it has kept the size much larger since this includes char[] .
The NetBeans profiler probably gives you a small size, which is not very useful, but easy to calculate. The saved size will include the use of char[] memory in the use of String memory, but calculating the stored size is expensive computational, and therefore profilers will not work until explicitly specified.
skaffman
source share