Reviewed
I am still trying to figure out why long
and double
in Java consuming 12 bytes
instead of 8 bytes
in memory
Sure there is wrong assumptions somewhere; please guide me..
I have analyzed it using two ways,
Following is my logic/assumption/source info,
- Define a single float or long property in a class and check its memory footprint
- Object will carry its own Meta Data worth
12 bytes = [CLASS INFO OF 4 BYTES] + [FLAGS INFO OF 4 BYTES] + [LOCK INFO OF 4 BYTES]
- Class size will be
Total Memory - Meta Data
- Result received is
12 bytes => 24 bytes (Total Memory) - 12 bytes (Meta Data)
- JDK: 1.8.0_65; Java HotSpot(TM) 64-Bit Server VM
- OS: Windows 8.1
- Test program
[ANSWER] Difference of 4 bytes is owing to Padding Applied by JVM. Thanks Andy Turner...