Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the size of reference variable in java [duplicate]

Tags:

java

core

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.

like image 782
chinmay Avatar asked Jul 23 '13 15:07

chinmay


People also ask

How big is a reference variable?

It depends on OS version in windows. The size of the reference itself will depend on your processor architecture - 4 bytes on 32-bit, 8 bytes on 64-bit. The reference itself is basically a pointer. 32 bits on a 32 bit OS, 64 bits on a 64 bit OS.

What is reference variable in Java?

Reference variable is used to point object/values. 2. Classes, interfaces, arrays, enumerations, and, annotations are reference types in Java. Reference variables hold the objects/values of reference types in Java.

How many bytes is a reference variable?

why reference size is always 4 bytes - c++

Can multiple variable reference a same object in memory?

Yes, two or more references, say from parameters and/or local variables and/or instance variables and/or static variables can all reference the same object.


1 Answers

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.
like image 193
assylias Avatar answered Oct 21 '22 04:10

assylias