4

In the following code:

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

...can heavy be garbage collected before or during doOtherStuff()? JLS references preferred, though actual experiments would be cool too.

My goal is to determine whether or not heavy = null is strictly useless, or might conceivably have some benefit.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413

0 Answers0