donaricano-btn

Garbage Collection

- Garbage Collection is process of reclaiming the runtime unused memory automatically

- It is a way to destroy the unused objects

- Java is performed automatically, Java provides better memory management


1. Advantage

- It makes java memory efficient

- It is automatically done by the garbage collector(a part of JVM)


2. How can an object be unreferenced?

- By nulling the reference

- By assigning a reference to another

- By annoymous object etc


1) By nulling a reference


2) By assigning a reference to another

 

3) By annonymous object

 

3. finalize() method

- The finalize() is invoked each time before the object is garbage collected

- It can be used to perform cleanup processing

 

1) point

- The garbage collector collects only those objects that are created by new keyword

- If you have created any object without new, you can use finalize method to perform cleanup processing


4. gc() method

- gc() is used to invoke the garbage collector to perform cleanup processing

- gc() is found in System and Runtime classes

 

1) point

- Garbage collection is performed by a daemon thread called GC

- This thread calls the finalize() before object is garbage collected



'Back-End > Java_1' 카테고리의 다른 글

[Java] JDK 환경변수 설정(configure) - Window10  (0) 2016.11.13
[Java] Shutdown Hook  (0) 2016.10.10
[Java] Thread pool  (0) 2016.10.10
[Java] Daemon Thread  (0) 2016.10.10
[Java] Thread Priority  (0) 2016.10.07
블로그 이미지

리딩리드

,