Calculating the memory usage by a String in JVM - JOL Footprint
 · 7 min read
In short:
- The memory of the String object consists of 24 bytes for metadata + the number of characters times 1 byte or 2 bytes depending on the coder value
- Metadata: mark word x2 (4 bytes x2 = 8 bytes), class word (4 bytes), array reference byte[] or char[] (4 byte), hash (4 byte), hashIsZero (1 byte), coder (1 byte), padding (2 byte)
 
- The String object has 2 additional flags:
- when coder =1then UTF-16 encoding (2 bytes per character)
- when coder = 0then LATIN-1 encoding (1 byte per character)
- hashIsZero is a flag that tells whether the hash calculation has already been performed
 
- when 
