0

How much space in memory in bytes does reference data types in java consume? Basically how many bytes do variables of class type take up, similar to int data type consuming 4 bytes.

3
  • Why do you think reference would allocate space and not object itself? Commented Oct 24, 2015 at 6:14
  • 4
    Possible Duplicate of stackoverflow.com/questions/258120/… Commented Oct 24, 2015 at 6:15
  • Yeah as the link says, generally accepted answer is 8 bytes. I think it might be more on 64 bit run times though if you're using 64 bit pointers in the JVM. Commented Oct 24, 2015 at 6:21

1 Answer 1

1

A reference variable is a pointer, and has the size of a pointer, so it depends on the JVM (32-bit or 64-bit), and whether pointers are compressed (compressedOop).

This is the space of the reference, not the Object potentially referenced by the variable (when not null).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.