Memory management in java
Where objects,variable variables,temp开发者_运维知识库orary variable are stored in java? How they are referenced? I know that methods are being stored in stack. where variables are stored heap or stack?
Where objects,variable variables,temporary variable are stored in java?
Objects are stored on the heap. Always.
Object fields / attributes are parts of their respective objects. I assume that's what you mean by "variable variables".
Local variables and method parameters are stored on the stack.
Note: if a field, variable, parameter has an object or array, the corresponding values will be represented in the "slot" for the object field / local variable / parameter by an object reference.
How they are referenced?
Objects are referenced by object references. How these object references are represented is an implementation detail which is JVM specific and opaque to an application program. However, in most cases, they are plain 32-bit or 64-bit machine (virtual) addresses.
精彩评论