Reputation: 617
What is the memory overhead of a single entry in Java HashMap? (using 64-bit Oracle Hotspot JVM). For example: is it 24 or 32 bytes?
Upvotes: 1
Views: 162
Reputation: 159165
The size of a HashMap.Entry
(Java 6) or HashMap.Node
(Java 8), both of which has one int
and three references.
If a reference is 4 bytes (compressed OOPS), then 12 bytes header + 4 byte int
+ 3 * 4 byte reference = 28 bytes, rounded to 32 bytes to fit on 8-byte boundary.
If a reference is 8 bytes, then 16 bytes header + 4 byte int
+ 3 * 8 byte reference = 44 bytes, rounded to 48 bytes to fit on 8-byte boundary.
Upvotes: 1
Reputation: 5828
An HashMap collection takes 32 bytes for each entry plus 4 bytes * map capacity for entries array.
Upvotes: 0