JAVA

GarbageCollector

이파댥 2024. 5. 16. 19:56

GarbageCollector

 

더이상 사용되지 않는 객체나 변수를 자동으로 정리하는 방식

안쓰는 것 청소해서 정리하기

 

public class GarbageCollector {
	// main 메서드 들어가기 전에 작성하는 변수가 전역변수
    
public static void main(String[] args) {
	// 지역변수 { } 안에 들어와서 작성을 했기 때문
	String address = "https://";
	System.out.println(address);

	address += "http://www.naver.com";
	System.out.println(address);
    }
}

 

 

public class GarbageCollector{
	
	public static void main(String[] args) {
		String Ph_number = "010"; // 가비지 컬렉션에 의해 Heap 에서 사라짐
		System.out.println(Ph_number); // 가비지 컬렉션에 의해 Heap 에서 사라짐
		
		Ph_number += "-1234-5678";
		System.out.println(Ph_number);

	}
}