10

What is the size of reference variables in java? I am quite sure it wont be dependent upon the architecture or is it? Does it bear any resemblance with concept of pointers in C? I have tries but could not get any convincing answer.

chinmay
  • 850
  • 2
  • 8
  • 16

1 Answers1

13

The amount of memory used by a reference depends on several parameters:

  • on a 32-bit JVM, it will be 32 bits
  • on a 64-bit JVM, it can be 32 or 64 bits depending on configuration. On hotspot for example, compressed ordinary object pointers is activated by default and the size of a reference is 32 bits. If you deactivate the option with -XX:-UseCompressedOops, they will use 64 bits.
assylias
  • 321,522
  • 82
  • 660
  • 783
  • 1
    you can get `32 bits` references size even without `CompressedOops`, like [this](https://stackoverflow.com/a/62664346/1059372) for example – Eugene Jun 30 '20 at 18:57