What is the size of the object in java

后端 未结 5 2001
半阙折子戏
半阙折子戏 2020-12-11 19:16

As we all know that java uses the following data types

byte    Occupy 8 bits in memory
short   Occupy 16 bits in memory
int     Occupy 32 bits in memory
long         


        
5条回答
  •  北海茫月
    2020-12-11 19:17

    The in-memory size of the object depends on the architecture, mainly on whether the VM is 32 or 64-bit. The actual VM implementation also matters.

    For each object, you need space for its object header (typically 2*8 bytes on 64-bit VMs), its fields (extra space for alignment depending on the VM implementation). The final space is then rounded up to the nearest multiple of the word size.

提交回复
热议问题