-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCDemo.java
More file actions
16 lines (16 loc) · 733 Bytes
/
Copy pathGCDemo.java
File metadata and controls
16 lines (16 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class GCDemo{
public static void main(String[] args){
//object creation
Object obj1=new Object();//obj1 refers to Object A
Object obj2=new Object();//obj2 refers to Object B
//object reference
obj1=obj2; //obj1 is reference of object B
obj2=null;// obj2 is reference of null so it refers no object
//so object A is eligible for Garbage collection and object B isn't
System.gc();//requesting JVM for garbage collection
@Override
protected void finalize() throws Throwable{
System.out.println("Succesfully ran garbage collection!!!");//something is wrong in this part of code, finalize() is deprecated from java.
}
}
}