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.
-
Why do you think reference would allocate space and not object itself?SMA– SMA2015-10-24 06:14:46 +00:00Commented Oct 24, 2015 at 6:14
-
4Possible Duplicate of stackoverflow.com/questions/258120/…Rahman– Rahman2015-10-24 06:15:14 +00:00Commented 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.markspace– markspace2015-10-24 06:21:30 +00:00Commented Oct 24, 2015 at 6:21
Add a comment
|
1 Answer
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).