0

enter image description hereHere is a char array with length 1024. I dump Java program run in Java8 into a hprof file. I find the size of char[1024] is 2072.

In my opinion, empty char array takes header(8 bytes) plus reference(4 bytes) plus length(int 4 bytes). So size of empty char array is 16 bytes.

So total size of char[1024] should be 1024 * 2 + 16 = 2064 bytes.

I use Java 1.8 and run in jvm 1.8.0_333

Michael
  • 41,989
  • 11
  • 82
  • 128
CoXier
  • 2,523
  • 8
  • 33
  • 60
  • 1
    possible duplicate of [JNA: Computed size of char array member of a struct is surprising](https://stackoverflow.com/questions/57843556/jna-computed-size-of-char-array-member-of-a-struct-is-surprising) – geocodezip Jun 14 '22 at 13:14
  • 2
    [What Heap Dumps Are Lying To You About](https://shipilev.net/blog/2014/heapdump-is-a-lie/) – Holger Jun 14 '22 at 14:57

0 Answers0