일하면서 후배에게 좋은 코드에 대해서 이런저런 얘기들을 해줬었는데,

글로 정리해뒀길래 링크해둡니다.


http://blog.geun.kr/243



P.s 

 - 해당 내용은 제 개인적인 생각이 반영되어 있습니다.

 - 개인적으로는 "7. 잘된 소스 보기" 가 실력을 올리는 가장 빠른 방법인 것도 같습니다.


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