public class GCTest {
     private final static int ALLOC_SIZE = (int)(Runtime.getRuntime().maxMemory() * 0.50);

     public static void main(String[] args) throws InterruptedException {
          System.out.println("Before first allocation");
          byte[] b = new byte[ALLOC_SIZE];
          b = null; //객체 레퍼런스 주소를 반환 처리함으로써 GC대상에 포함되게 됨(null 처리 안하면 full gc 발생하면서 프로그램 종료됨)
          System.out.println("After first allocation");
          //        Thread.sleep(5000);
          System.out.println("Before second allocation");
          byte[] b2 = new byte[ALLOC_SIZE];
          System.out.println("After second allocation");
     }
}

+ Recent posts