What is the memory consumption of an object in Java?

前端 未结 12 2317
眼角桃花
眼角桃花 2020-11-22 03:20

Is the memory space consumed by one object with 100 attributes the same as that of 100 objects, with one attribute each?

How much memory is allocated for an object?<

12条回答
  •  清酒与你
    2020-11-22 03:46

    It appears that every object has an overhead of 16 bytes on 32-bit systems (and 24-byte on 64-bit systems).

    http://algs4.cs.princeton.edu/14analysis/ is a good source of information. One example among many good ones is the following.

    enter image description here

    http://www.cs.virginia.edu/kim/publicity/pldi09tutorials/memory-efficient-java-tutorial.pdf is also very informative, for example:

    enter image description here

提交回复
热议问题