스택 영역과 힙 영역


<aside> 🚚

예제


package memory;

public class JavaMemoryMain2 {
	public static void main(String[] args) {
		System.out.println("main start");
		method1();
		System.out.println("main end");
	}
		
	static void method1() {
		System.out.println("method1 start");
		Data data1 = new Data(10);
		method2(data1);
		System.out.println("method1 end");
	}
	
	static void method2(Data data2) {
		System.out.println("method2 start");
		System.out.println("data.value=" + data2.getValue());
		System.out.println("method2 end");
	}
}

출력
main start
method1 start
method2 start
data.value=10
method2 end
method1 end
main end

동작 순서


첫 번째

image.png

두 번째

image.png

세 번째

image.png

네 번째

image.png

다섯 번째

image.png

여섯 번째

image.png

</aside>

핵심


<aside> ✂️

설명


스택 영역, 힙 영역 자세히 구분 - 위 코드 참조


<aside> 🥇

설명


image.png

image.png

image.png

image.png

image.png

</aside>