Java Garbage Collector -
Garbage Collector in Java working for release the memory form waste (unreachable) object.
Garbage Collector works with heap memory.
Any Object is created in Java it goes to the heap memory. When this object is being waste or unreachable then Garbage Collector release memory from its.
Understand about waste or unreachable object -
String s = new String(“Albert”);
String s1 = new String (“Another”);
in this case new String (“Another”); has been waste object.
Then Garbage collector will release the memory form this object.
Garbage Collector called by JVM directly. You can not force for release the memory.
You can request to Garbage Collector through System.gc() method.
For tracing the event of Garbage Collection use this command