I am currently studying the concepts of java memory, stack and heap, I know that local variables and method calls lived in a place called a stack. and the objects lived inside the heap. but what if this local variable contains an object? or has a link to an object?
public void Something(){ Duck d = new Duck(24); }
Does he still live inside the stack? and where do instance variables live? Please keep it as simple as possible. thank.
A local variable d(allocated on the stack) contains a reference to the class object Duck. In general, objects are allocated on the heap.
d
Duck
Java 6e14 -, "escape-". -XX:+DoEscapeAnalysis switch, , JVM , , , , "" , , . JVM ( , ). , , .
-XX:+DoEscapeAnalysis
, , .
. , - , stack.else, refrence , .