Garbage Collection in java

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.