Ways to make an object eligible for GC

https://www.geeksforgeeks.org/how-to-make-object-eligible-for-garbage-collection/

There are generally four different ways to make an object eligible for garbage collection.

    1. Nullifying the reference variable
    2. Re-assigning the reference variable
    3. Object created inside method
    4. Island of Isolation

1.Object created inside a method :

When a method is called it goes inside the stack frame. When the method is popped from the stack, all its members dies and if some objects were created inside it then these objects becomes unreachable or anonymous after method execution and thus becomes eligible for garbage collection

2.Reassigning the reference variable:

When reference id of one object is referenced to reference id of some other object then the previous object has no any longer reference to it and becomes unreachable and thus becomes eligible for garbage collection.

3.Nullifying the reference variable :

When all the reference variables of an object are changed to NULL, it becomes unreachable and thus becomes eligible for garbage collection.

4.Anonymous object :

The reference id of an anonymous object is not stored anywhere. Hence, it becomes unreachable.

results matching ""

    No results matching ""