Sobes.tech
Junior — Middle

What is the approximate amount of memory occupied by a basic object instance in Java?

sobes.tech AI

Answer from AI

The approximate size of a basic object instance in Java depends on the JVM implementation and architecture (32-bit or 64-bit). Typically, an object contains:

  • Object header, which occupies about 8-16 bytes. In 64-bit JVMs with compressed pointers enabled, about 12 bytes.
  • Object fields (none in the basic Object).
  • Memory padding for alignment.

Thus, an empty Object usually occupies about 12-16 bytes in a 64-bit JVM with pointer compression.

This is an estimate; the exact size can be determined using profiling tools or special libraries, such as Instrumentation.getObjectSize().

What is the approximate amount of memory occupied by… - sobes.tech