Garbage Collection
Garbage Collection
Garbage Collection
test=null; => When you execute this, the reference is deleted but
the memory occupied by the object is not released.
Runtime rs = Runtime.getRuntime();
rs.gc();
import java.util.*;
class GarbageCollection {
public static void main(String s[]) throws Exception {
Runtime rs = Runtime.getRuntime();
System.out.println("Free memory in JVM before Garbage
Collection = "+rs.freeMemory());
rs.gc();
System.out.println("Free memory in JVM after Garbage
Collection = "+rs.freeMemory()); } }
• By using finalization, you can define specific actions that will occur
when an object is just about to be reclaimed by the garbage collector
• Inside the finalize( ) method, you will specify those actions that must be
performed before an object is destroyed