Where are instance variables (primitives) stored in java? In any case, is the stack associated with instance variable storage?

Where are instance variables (primitives) stored in java?

+4
source share
3 answers

Primitive variables are stored in the same places where all variables are stored (including references):

  • Inside objects created (allocated) on the heap, or
  • Inside the frames of the method stack as local variables or
  • Within the static areas of their containing class (which are on the heap).
+7
source

If you mean instances of fields declared in a class, they are allocated on the heap as part of the object's own allocation.

Primitive variables (value type) declared as method locators are stored in the method stack frame.

+2
source

After loading the class, the class loader with the qualified name in jvm. The JVM parses binary data from the class and places this information in the Method area. When the JVM executes the class, it first places objects (including primitive / non-primitive field instances) in the heap.

0
source

All Articles