When Is An Object Subject To Garbage Collection
an object is subjected to garbage collection if it is left unused for a long time.
Student s1= new Student();
Student s2= new Student();
like this if we keep on using s1 and left s2 then after some amount of time it is subjected to garbage collection.
if an object is not reachable then that object is eligible for garbage collection. Here reachable means we dont have anyway to access that object. that means no reference variable holds that object, simply object is present in heap memory but no reference variable points to that object. in this case object is eligible for garbage collection.
An object is subject to garbage collection when it becomes unreachable to the program in which it is used.
2009-2016 downloadmela.com. All rights reserved.