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.
            Asked
            
        
        
            Active
            
        
            Viewed 5,672 times
        
    10
            
            
        - 
                    2See here http://stackoverflow.com/questions/5350950/reference-type-size-in-java – John Snow Jul 23 '13 at 15:19
- 
                    Or here: http://stackoverflow.com/questions/16882277/how-to-find-objects-size-including-contained-objects – William Morrison Jul 23 '13 at 15:21
- 
                    1Size will be dependent on the architecture of the virtual machine. – William Morrison Jul 23 '13 at 15:22
- 
                    2What does it matter? How would you tell if the reference is 32 bits or 64 or 128? What difference could it possibly make in the execution of a program (other than the amount of heap required)? – Hot Licks Jul 23 '13 at 15:23
1 Answers
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
- 
                    1you 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
