728x90

JVM

JVM에서 Object는 반드시 Heap 영역에 생성된다. Heap 메모리에 생성되는 자바 Object는 두개의 Area를 가진다.

      1. header area – pointer to object

      2. data area – values for instance variables of object

Java Hotspot virtual machine은 객체 header에 2 machine word를 사용( 32bit에서 1 machine-word는 4byte). 만약 객체가 Array라면 3개의 machine word를 사용(Array의 length)

     1. classptr – pointer to the class information

     2. hash+age+lock – object’s hash code, age information, lock fields

     3. array length – 배열인 경우만 생성

GC 실행

1
2
3
4
5
6
7
8
9
10
11
12
package com.goodcodes.io;
 
public class GCTest {
 
    public static void main(String[] args) {
        // Runtime instance 의 사용
        Runtime rt=Runtime.getRuntime();
        rt.gc();
        // 시스템 편의 유틸
        System.gc();
    }
}

Object Finalization

Object가 GC되기 전의 행동을 정한다.

Object의 finalize() 클래스를 override한다.

Garbage Collection in JAVA

1. Reference Counting

   참조변수에 Object의 참조가 할당되면 count를 1 늘리고 참조가 사라지면 count를 1을 줄여서 0가 되면 GC의 대상으로

2. Tracing Algorithm (root set)

   Referece


Reference

보통 캐싱목적으로 사용 GC의 대상

1. Soft Reference

2. Weak Reference

3. Phantom Reference

 

출처 : http://goodcodes.tistory.com/116

728x90

'JAVA' 카테고리의 다른 글

JVM. GARBAGE COLLECTION 모니터링  (0) 2014.11.28
JAVA GARBAGE COLLECTION  (0) 2014.11.28
interface 추상클래스 차이  (0) 2014.11.27
OOP 4가지 특성  (0) 2014.11.12
OOD(객체지향설계)  (0) 2014.11.12

+ Recent posts