If an object is un attended and no longer referenced. Such objects are known as garbage and autometically destroyed by JVM (Java Virtual Machine).
It’s look like a magic because you don’t have to worry about memory management in java.
Consider class Student from the previous article
garabage collection Example
Student s1 = new Student();
Student s2 = new Student();
refrence of s1 is updated to the same object referenced by s2. s1 is no longer referenced by the previous object, such objects are known as garbage and JVM will handle them autometically.