I was going through the Java
Garbage Collection process and different scenarios in which GC
is applicable.
Below is the scenario I am confused about :
List<X> listX = new ArrayList<X>();
for(int a = 0;a<100;a++){
listX.add(new X(a));
}
for (X xObject : listX) {
xObject.printValue();
}
In the first loop I am adding the new objects in each loop and in the latest loop I am just printing the values, so, are those objects which I am adding in the list applicable for GC
?
What does this sentence mean ?
"One more excellent example for when an instance can become eligible for garbage collection. All the properties of an instance can be stored in the register and thereafter the registers will be accessed to read the values. There is no case in future that the values will be written back to the instance. Though the values can be used in future, still this instance can be marked eligible for garbage collection"