Caveats.

Typical memory usage for objects in java

1. primitive types

Typical memory usage for objects in java

Typical memory usage for objects in java


Object overhead. 16 bytes.

Reference. 8 bytes.

Padding. Each object uses a multiple of 8 bytes.

Typical memory usage for objects in java


Typical memory usage for objects in java



Typical memory usage for objects in java

Shallow memory usage: Don’t count referenced objects.

Deep memory usage: If array entry or instance variable is a reference, add memory (recursively) for referenced object.


Typical memory usage for objects in java


Q. What is the purpose of padding?
A. Padding makes all objects take space that is a mulitple of 8 bytes. This can waste some memory but it speeds up memory access and garbage collection.

相关文章: