My question or rather questions are as follows:
1)Where does the static variable reside . Some articles say they reside on the heap and some some say in the perm gen area with the class definition as they are class attributes. I understand the second option might be correct because it is a class attribute.
2)Where does the final variable reside and what is its life if:
a) Its an instance variable of type primitive
b) Its a local variable of a method of type primitive
c) Its an instance variable of type reference
b) Its a local variable of a method of type reference
3)Where are the reference local variables stored if they are local.
4)In case of arrays is there any difference in memory allocation as in they are instance variable or local thread variable.
Thanks
Where does the static variable reside– static variable resides in
Method Area, and permgen is inside Method area.– If its instance variable, it stays on the
Heap inside the Objectto which it belongs, and falls out of scope as there is no reference to the Object which holds it..Its a local variable of a method of type primitive– It stays on the Stack, and and falls out of scope as there as the methods closing brace is reached…
Its an instance variable of type reference– it stays on the
Heap inside the Objectto which it belongs, and falls out of scope as there is no reference to the Object which holds it..Its a local variable of a method of type reference– It stays on the Stack, and and falls out of scope as there as the methods closing brace is reached…
Where are the reference local variables stored if they are local.– On the Stack…
In case of arrays is there any difference in memory allocation as in they are instancevariable or local thread variable.– Well as Array is an object it is stored on
Heap….but fromJava 6u23version, there has been the introduction ofEscape Analysis, according to this if the JVM decides that the Object canNot escape the Method, it will try creating the Object on the Thread’s Stack , NOT ON HEAP….