[Solved] Garbage collector in java

At least two, potentially all three of them. Since the local variables are not used after line 11 the JVM is free to set them to null, and they become eligible for garbage collection. From JLS 12.6.1:

Optimizing transformations of a program can be designed that reduce the number of objects that are reachable to be less than those which would naively be considered reachable. For example, a Java compiler or code generator may choose to set a variable or parameter that will no longer be used to null to cause the storage for such an object to be potentially reclaimable sooner.

This can be observed to happen in practice on the Hotspot JVM (see for example The JVM ate my variable!).


solved Garbage collector in java