0

Could anyone make me understand the term "object header" and "padding" in java?

class A{

int a;

}

what "object header" and "padding" would be here ?

Mohsin AR
  • 2,816
  • 1
  • 22
  • 36
  • possible duplicate of [What is the memory consumption of an object in Java?](http://stackoverflow.com/questions/258120/what-is-the-memory-consumption-of-an-object-in-java) – Turing85 Jun 11 '15 at 17:51

1 Answers1

4

"Padding" is the tendency of objects in Java to be a multiple of 8 due to memory alignment: Why do Java objects have to be a multiple of 8?

All objects in Java contain an "object header" with a bit of extra overhead information (causing them to take up a little extra space): What is in java object header

So in your example, there would be space taken up by the header for class A along with the space needed to hold it's field int a. If these two values did not add up to a multiple of 8, extra space would be added to the memory location so that it was a multiple of 8, and therefore properly aligned in memory.

Community
  • 1
  • 1
River
  • 8,031
  • 13
  • 51
  • 64