Can Java GC local variables be present in scope but are no longer used?

In the following code:

void method() {
   HeavyObject heavy = new HeavyObject();
   doStuffWith(heavy);
   doOtherStuff();
}

... can it heavycollect garbage before or during doOtherStuff()? JLS recommendations are preferred, although real experiments would also be cool.

My goal is to determine whether or not it is heavy = nullcompletely useless or possibly has a certain benefit.

+4
source share

Source: https://habr.com/ru/post/1599190/


All Articles